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 a5c87273772..c2fd42a329c 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 @@ -12,6 +12,66 @@ import kotlin.test.assertTrue class NpmRangeTest { @Test fun maxStartWith() { - assertTrue { false } + val nullRange1 = npmRange() + val nullRange2 = npmRange() + val maxStart1 = maxStart( + nullRange1, + nullRange2 + ) + assertTrue("Max start should be ${nullRange2.startVersion} but $maxStart1 found") { + maxStart1 == nullRange2.startVersion + } + + val startRange1 = npmRange( + startMajor = 1 + ) + val maxStart2 = maxStart( + startRange1, + npmRange() + ) + assertTrue("Max start should be ${startRange1.startVersion} but $maxStart2 found") { + maxStart2 == startRange1.startVersion + } + + val startRange2 = npmRange(startMajor = 2) + val maxStart3 = maxStart( + startRange1, + startRange2 + ) + assertTrue("Max start should be ${startRange2.startVersion} but $maxStart3 found") { + maxStart3 == startRange2.startVersion + } } -} \ No newline at end of file +} + +private fun npmRange( + startMajor: Int? = null, + startMinor: Int? = null, + startPatch: Int? = null, + endMajor: Int? = null, + endMinor: Int? = null, + endPatch: Int? = null, + startInclusive: Boolean = false, + endInclusive: Boolean = false +): NpmRange = + NpmRange( + startVersion = semVer(startMajor, startMinor, startPatch), + endVersion = semVer(endMajor, endMinor, endPatch), + startInclusive = startInclusive, + endInclusive = endInclusive + ) + +private fun semVer( + major: Int? = null, + minor: Int? = null, + patch: Int? = null +): SemVer? = + if (major == null && minor == null && patch == null) + null + else { + SemVer( + (major ?: 0).toBigInteger(), + (minor ?: 0).toBigInteger(), + (patch ?: 0).toBigInteger() + ) + } \ No newline at end of file