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::Core::CsvParser do
describe '.parse' do
subject { described_class.parse(line) }
context 'when parsing a single line of csv' do
let(:line) { '"spandx","0.0.0","MIT"' + "\n" }
specify { expect(subject).to eql(['spandx', '0.0.0', 'MIT']) }
end
context 'when parsing a line of csv that contains a `,` in the value' do
let(:line) { '"spa,ndx","0.0.0","MIT"' + "\n" }
specify { expect(subject).to eql(['spa,ndx', '0.0.0', 'MIT']) }
end
context 'when parsing a line of csv that contains empty name' do
let(:line) { '"","0.0.0","MIT"' }
specify { expect(subject).to eql(['', '0.0.0', 'MIT']) }
end
context 'when parsing a line of csv that contains empty version' do
let(:line) { '"AWSSDK.Organizations","","MIT"' }
specify { expect(subject).to eql(['AWSSDK.Organizations', '', 'MIT']) }
end
context 'when parsing a line of csv that contains empty license' do
let(:line) { '"AWSSDK.Organizations","3.3.8.12",""' }
specify { expect(subject).to eql(['AWSSDK.Organizations', '3.3.8.12', '']) }
end
context 'when parsing an invalid line of csv' do
specify { expect(described_class.parse(nil)).to be_nil }
specify { expect(described_class.parse('"","",""')).to eql(['', '', '']) }
specify { expect(described_class.parse('"","0.0.0",""')).to eql(['', '0.0.0', '']) }
specify { expect(described_class.parse('"hello O"world","0.1.0"')).to eql(['hello O"world', '0.1.0']) }
specify { expect(described_class.parse('"hello O"world","0.1.0",""')).to eql(['hello O"world', '0.1.0', '']) }
specify { expect(described_class.parse('invalid","3.3.8.12",""')).to be_nil }
end
end
end
|