@@ -98,6 +98,129 @@ describe('SPDX utility functions', () => {
98
98
} )
99
99
} )
100
100
101
+ it ( 'parses licenseRef with lookup' , ( ) => {
102
+ const data = new Map ( [
103
+ [ 'afpl-9.0' , { license : 'LicenseRef-scancode-afpl-9.0' } ] ,
104
+ [ '(afpl-9.0)' , { license : 'LicenseRef-scancode-afpl-9.0' } ] ,
105
+ [
106
+ '(afpl-9.0 OR Apache-2.0)' ,
107
+ {
108
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
109
+ conjunction : 'or' ,
110
+ right : { license : 'Apache-2.0' }
111
+ }
112
+ ] ,
113
+ [
114
+ 'Apache-2.0 AND (afpl-9.0)' ,
115
+ {
116
+ left : { license : 'Apache-2.0' } ,
117
+ conjunction : 'and' ,
118
+ right : { license : 'LicenseRef-scancode-afpl-9.0' }
119
+ }
120
+ ] ,
121
+ [
122
+ 'Apache-2.0 AND (afpl-9.0 AND afpl-9.0)' ,
123
+ {
124
+ left : { license : 'Apache-2.0' } ,
125
+ conjunction : 'and' ,
126
+ right : {
127
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
128
+ conjunction : 'and' ,
129
+ right : { license : 'LicenseRef-scancode-afpl-9.0' }
130
+ }
131
+ }
132
+ ] ,
133
+ [
134
+ '(afpl-9.0 AND afpl-9.0) AND Apache-2.0' ,
135
+ {
136
+ right : { license : 'Apache-2.0' } ,
137
+ conjunction : 'and' ,
138
+ left : {
139
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
140
+ conjunction : 'and' ,
141
+ right : { license : 'LicenseRef-scancode-afpl-9.0' }
142
+ }
143
+ }
144
+ ] ,
145
+ [
146
+ 'Apache-2.0 AND (afpl-9.0 OR afpl-9.0)' ,
147
+ {
148
+ left : { license : 'Apache-2.0' } ,
149
+ conjunction : 'and' ,
150
+ right : {
151
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
152
+ conjunction : 'or' ,
153
+ right : { license : 'LicenseRef-scancode-afpl-9.0' }
154
+ }
155
+ }
156
+ ] ,
157
+ [
158
+ 'MIT AND GPL-3.0' ,
159
+ {
160
+ left : { license : 'MIT' } ,
161
+ conjunction : 'and' ,
162
+ right : { license : 'GPL-3.0' }
163
+ }
164
+ ] ,
165
+ [
166
+ 'AFL-1.1 AND afpl-9.0' ,
167
+ {
168
+ left : { license : 'AFL-1.1' } ,
169
+ conjunction : 'and' ,
170
+ right : { license : 'LicenseRef-scancode-afpl-9.0' }
171
+ }
172
+ ] ,
173
+ [
174
+ 'afpl-9.0 AND MIT' ,
175
+ {
176
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
177
+ conjunction : 'and' ,
178
+ right : { license : 'MIT' }
179
+ }
180
+ ] ,
181
+ [
182
+ 'afpl-9.0 AND activestate-community' ,
183
+ {
184
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
185
+ conjunction : 'and' ,
186
+ right : { license : 'LicenseRef-scancode-activestate-community' }
187
+ }
188
+ ] ,
189
+ [
190
+ 'afpl-9.0 AND activestate-community OR ac3filter' ,
191
+ {
192
+ left : {
193
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
194
+ conjunction : 'and' ,
195
+ right : { license : 'LicenseRef-scancode-activestate-community' }
196
+ } ,
197
+ conjunction : 'or' ,
198
+ right : { license : 'LicenseRef-scancode-ac3filter' }
199
+ }
200
+ ] ,
201
+ [ 'INVALID' , { noassertion : null } ] ,
202
+ [
203
+ 'LicenseRef-scancode-afpl-9.0 AND MIT' ,
204
+ {
205
+ left : { license : 'LicenseRef-scancode-afpl-9.0' } ,
206
+ conjunction : 'and' ,
207
+ right : { license : 'MIT' }
208
+ }
209
+ ]
210
+ ] )
211
+
212
+ const licenseRefLookup = function ( identifier ) {
213
+ if ( identifier === 'afpl-9.0' ) return 'LicenseRef-scancode-afpl-9.0'
214
+ if ( identifier === 'activestate-community' ) return 'LicenseRef-scancode-activestate-community'
215
+ if ( identifier === 'ac3filter' ) return 'LicenseRef-scancode-ac3filter'
216
+ return identifier
217
+ }
218
+
219
+ data . forEach ( ( expected , input ) => {
220
+ expect ( SPDX . parse ( input , undefined , licenseRefLookup ) ) . to . deep . equal ( expected )
221
+ } )
222
+ } )
223
+
101
224
it ( 'stringifies spdx objects' , ( ) => {
102
225
const data = new Map ( [
103
226
[ { license : 'MIT' } , 'MIT' ] ,
0 commit comments