From 50ccb522b9b679c10a9cbe825b28527773045dfb Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Thu, 6 Aug 2020 18:29:15 +0300 Subject: [PATCH] [Gradle, JS] Add intersect tests ^KT-41054 fixed --- .../gradle/targets/js/npm/NpmRangeTest.kt | 118 +++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmRangeTest.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmRangeTest.kt index 6b4df1e3bf2..f8c4aa712ff 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmRangeTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/NpmRangeTest.kt @@ -10,6 +10,83 @@ import kotlin.test.assertTrue class NpmRangeTest { + @Test + fun intersectTest() { + fun assertIntersect(range1: NpmRange, range2: NpmRange, expected: NpmRange?) { + val intersection = range1 intersect range2 + assertTrue("Range $range1 and $range2 expected to have intersection $expected, but actual is $intersection") { + intersection == expected + } + + val symIntersection = range2 intersect range1 + assertTrue("Range $range2 and $range1 expected to have union $expected, but actual is $symIntersection") { + symIntersection == expected + } + } + + val range1 = npmRange(startMajor = 1, endMajor = 2) + val range2 = npmRange(startMajor = 3, endMajor = 4) + assertIntersect(range1, range2, null) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 3), + npmRange(startMajor = 2, endMajor = 4), + npmRange( + startMajor = 2, + endMajor = 3 + ) + ) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 3), + npmRange(startMajor = 2, endMajor = 4, startInclusive = true, endInclusive = true), + npmRange( + startMajor = 2, + endMajor = 3, + startInclusive = true + ) + ) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 3, startInclusive = true, endInclusive = true), + npmRange(startMajor = 2, endMajor = 4, startInclusive = true, endInclusive = true), + npmRange( + startMajor = 2, + endMajor = 3, + startInclusive = true, + endInclusive = true + ) + ) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 4, startInclusive = true, endInclusive = true), + npmRange(startMajor = 2, endMajor = 3, startInclusive = true, endInclusive = true), + npmRange( + startMajor = 2, + endMajor = 3, + startInclusive = true, + endInclusive = true + ) + ) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 2), + npmRange(startMajor = 2, endMajor = 3), + null + ) + + assertIntersect( + npmRange(startMajor = 1, endMajor = 2, endInclusive = true), + npmRange(startMajor = 2, endMajor = 3, startInclusive = true), + npmRange( + startMajor = 2, + endMajor = 2, + startInclusive = true, + endInclusive = true + ) + ) + } + @Test fun unionTest() { fun assertUnion(range1: NpmRange, range2: NpmRange, expected: List) { @@ -18,7 +95,7 @@ class NpmRangeTest { union == expected } - val symUnion = range1 union range2 + val symUnion = range2 union range1 assertTrue("Range $range2 and $range1 expected to have union $expected, but actual is $symUnion") { symUnion == expected } @@ -63,6 +140,45 @@ class NpmRangeTest { ) ) ) + + assertUnion( + npmRange(startMajor = 1, endMajor = 4, startInclusive = true, endInclusive = true), + npmRange(startMajor = 2, endMajor = 3, startInclusive = true, endInclusive = true), + listOf( + npmRange( + startMajor = 1, + endMajor = 4, + startInclusive = true, + endInclusive = true + ) + ) + ) + + assertUnion( + npmRange(startMajor = 1, endMajor = 2), + npmRange(startMajor = 2, endMajor = 3), + listOf( + npmRange( + startMajor = 1, + endMajor = 2 + ), + npmRange( + startMajor = 2, + endMajor = 3 + ) + ) + ) + + assertUnion( + npmRange(startMajor = 1, endMajor = 2, endInclusive = true), + npmRange(startMajor = 2, endMajor = 3, startInclusive = true), + listOf( + npmRange( + startMajor = 1, + endMajor = 3 + ) + ) + ) } @Test