File tree 2 files changed +28
-14
lines changed
2 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -310,24 +310,29 @@ class SpdxCompoundExpression(
310
310
right.validate(strictness)
311
311
}
312
312
313
- override fun validChoicesForDnf (): Set <SpdxExpression > =
314
- when (operator ) {
315
- SpdxOperator .AND -> setOf (decompose().reduce(SpdxExpression ::and ))
316
-
317
- SpdxOperator .OR -> {
318
- val validChoicesLeft = when (left) {
319
- is SpdxCompoundExpression -> left.validChoicesForDnf()
320
- else -> left.validChoices()
321
- }
313
+ override fun validChoicesForDnf (): Set <SpdxExpression > {
314
+ val validChoicesLeft = when (left) {
315
+ is SpdxCompoundExpression -> left.validChoicesForDnf()
316
+ else -> left.validChoices()
317
+ }
322
318
323
- val validChoicesRight = when (right) {
324
- is SpdxCompoundExpression -> right.validChoicesForDnf()
325
- else -> right.validChoices()
326
- }
319
+ val validChoicesRight = when (right) {
320
+ is SpdxCompoundExpression -> right.validChoicesForDnf()
321
+ else -> right.validChoices()
322
+ }
327
323
328
- validChoicesLeft + validChoicesRight
324
+ return when (operator ) {
325
+ SpdxOperator .AND -> {
326
+ validChoicesLeft.map { leftChoice ->
327
+ validChoicesRight.map { rightChoice ->
328
+ if (leftChoice == rightChoice) leftChoice else leftChoice and rightChoice
329
+ }
330
+ }.flatten().toSet()
329
331
}
332
+
333
+ SpdxOperator .OR -> validChoicesLeft + validChoicesRight
330
334
}
335
+ }
331
336
332
337
override fun offersChoice (): Boolean =
333
338
when (operator ) {
Original file line number Diff line number Diff line change @@ -439,6 +439,15 @@ class SpdxExpressionTest : WordSpec() {
439
439
" not contain duplicate valid choice different left and right expressions" {
440
440
" a AND a AND b" .toSpdx().validChoices() should containExactly(" a AND b" .toSpdx())
441
441
}
442
+
443
+ " return the correct choices for a mixed expression" {
444
+ val spdxExpression = " a AND (a OR b)" .toSpdx()
445
+
446
+ spdxExpression.validChoices() should containExactlyInAnyOrder(
447
+ " a" .toSpdx(),
448
+ " a AND b" .toSpdx()
449
+ )
450
+ }
442
451
}
443
452
444
453
" offersChoice()" should {
You can’t perform that action at this time.
0 commit comments