blob: 80ee503b15756bacdc24cc6f95eb9772fe4eb34a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# frozen_string_literal: true
RSpec.describe Spandx::Spdx::CompositeLicense do
describe '.from_expression' do
subject { described_class.from_expression(expression, catalogue) }
let(:catalogue) { ::Spandx::Spdx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
context 'when parsing a simple binary expression' do
let(:expression) { '(0BSD OR MIT)' }
specify { expect(subject.id).to eql('0BSD OR MIT') }
specify { expect(subject.name).to eql("#{catalogue['0BSD'].name} OR #{catalogue['MIT'].name}") }
specify { expect(subject).to be_kind_of(::Spandx::Spdx::License) }
end
context 'when parsing an expression with a valid and an invalid license id' do
let(:expression) { 'MIT or GPLv3' }
specify { expect(subject.id).to eql('MIT OR Nonstandard') }
specify { expect(subject.name).to eql("#{catalogue['MIT'].name} OR GPLv3") }
specify { expect(subject).to be_kind_of(::Spandx::Spdx::License) }
end
context 'when parsing a license name' do
let(:expression) { 'Common Public License Version 1.0' }
specify { expect(subject).to be_nil }
end
context 'when parsing an invalid expression' do
let(:expression) { 'BSD-like' }
specify { expect(subject.id).to eql('Nonstandard') }
specify { expect(subject.name).to eql('BSD-like') }
end
context 'when parsing a binary expression with an id that is similar to another' do
let(:expression) { '(MIT OR CC0-1.0)' }
specify { expect(subject.id).to eql('MIT OR CC0-1.0') }
specify { expect(subject.name).to eql("#{catalogue['MIT'].name} OR #{catalogue['CC0-1.0'].name}") }
specify { expect(subject).to be_kind_of(::Spandx::Spdx::License) }
end
end
end
|