Skip to content

Commit 6744276

Browse files
committed
Working license expression parser
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent 7c53cb7 commit 6744276

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,34 @@ public void testExternalCustomLicense() throws InvalidSPDXAnalysisException {
337337
}
338338

339339
public void testExternalLicenseAddition() throws InvalidSPDXAnalysisException {
340-
fail("Not implemented");
340+
String simpleParseString = NONSTD_IDS[0] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[0];
341+
SimpleLicensingAnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(simpleParseString,
342+
modelStore, DEFAULT_PREFIX, copyManager, doc);
343+
assertTrue(result instanceof ExpandedLicensingWithAdditionOperator);
344+
345+
assertEquals(EXTERNAL_CUSTOM_ADDITION_URIS[0], ((ExpandedLicensingWithAdditionOperator)result)
346+
.getExpandedLicensingSubjectAddition().getObjectUri());
347+
String complexParseString = STD_IDS[0] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[0] + " AND " +
348+
STD_IDS[0] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[1] + " AND " +
349+
STD_IDS[1] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[2] + " AND " +
350+
STD_IDS[2] + " WITH " + EXTERNAL_CUSTOM_ADDITION_TOKENS[3];
351+
result = LicenseExpressionParser.parseLicenseExpression(complexParseString,
352+
modelStore, DEFAULT_PREFIX, copyManager, doc);
353+
assertTrue(result instanceof ExpandedLicensingConjunctiveLicenseSet);
354+
Boolean[] found = new Boolean[] {false, false, false, false};
355+
Collection<SimpleLicensingAnyLicenseInfo> members = ((ExpandedLicensingConjunctiveLicenseSet)result).getExpandedLicensingMembers();
356+
assertEquals(4, members.size());
357+
for (SimpleLicensingAnyLicenseInfo member:members) {
358+
for (int i = 0; i < EXTERNAL_CUSTOM_ADDITION_URIS.length; i++) {
359+
assertTrue(member instanceof ExpandedLicensingWithAdditionOperator);
360+
if (((ExpandedLicensingWithAdditionOperator)member).getExpandedLicensingSubjectAddition().getObjectUri().equals(EXTERNAL_CUSTOM_ADDITION_URIS[i])) {
361+
found[i] = true;
362+
}
363+
}
364+
}
365+
for (Boolean foundIt:found) {
366+
assertTrue(foundIt);
367+
}
341368
}
342369

343370
public void regressionMitWith() throws InvalidSPDXAnalysisException, InvalidLicenseStringException {

0 commit comments

Comments
 (0)