Move scripting support classes to the scripting compiler impl module
This commit is contained in:
@@ -18,8 +18,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.util
|
||||
|
||||
import org.jetbrains.kotlin.script.tryCreateCallableMappingFromNamedArgs
|
||||
import org.jetbrains.kotlin.script.tryCreateCallableMappingFromStringArgs
|
||||
import org.jetbrains.kotlin.utils.tryCreateCallableMappingFromNamedArgs
|
||||
import org.jetbrains.kotlin.utils.tryCreateCallableMappingFromStringArgs
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import kotlin.reflect.KParameter
|
||||
@@ -30,22 +30,41 @@ class ArgsToParamsMatchingTest {
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf()))
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "2")))
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "2", "s", "0.1")),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "2", "s", "0.1")),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "258", "s", "0.1")))
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "258", "s", "0")))
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "258", "sss", "0.1")))
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "2", "s", "0.1", "abc", "true", "1", "2", "3")),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1, "s" to "abc", "t" to true, "v" to arrayOf(1L, 2L, 3L))
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromStringArgs(
|
||||
::foo,
|
||||
listOf("1", "2", "s", "0.1", "abc", "true", "1", "2", "3")
|
||||
),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1, "s" to "abc", "t" to true, "v" to arrayOf(1L, 2L, 3L))
|
||||
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("i", "b", "c")))
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::foo, listOf("1", "2", "s", "0.1", "abc", "true", "not-a-long")))
|
||||
Assert.assertNull(
|
||||
tryCreateCallableMappingFromStringArgs(
|
||||
::foo,
|
||||
listOf(
|
||||
"1",
|
||||
"2",
|
||||
"s",
|
||||
"0.1",
|
||||
"abc",
|
||||
"true",
|
||||
"not-a-long"
|
||||
)
|
||||
)
|
||||
)
|
||||
Assert.assertNull(tryCreateCallableMappingFromStringArgs(::charArray, listOf("")))
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromStringArgs(::varargStrings, listOf("a", "b", "c")),
|
||||
"s" to arrayOf("a", "b", "c"))
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromStringArgs(::varargStrings, listOf("a", "b", "c")),
|
||||
"s" to arrayOf("a", "b", "c"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,30 +72,75 @@ class ArgsToParamsMatchingTest {
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::foo, listOf()))
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2)))
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), null to 's', null to 0.1)),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(null to 1, null to 2.toByte(), null to 's', null to 0.1)
|
||||
),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), "c" to 's', "d" to 0.1)),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(null to 1, null to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), "d" to 0.1, "c" to 's')),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(null to 1, null to 2.toByte(), "d" to 0.1, "c" to 's')
|
||||
),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1)
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), null to 's', null to 0.1, "v" to arrayOf(1L, 2L, 3L))),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1, "v" to arrayOf(1L, 2L, 3L))
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(
|
||||
null to 1,
|
||||
null to 2.toByte(),
|
||||
null to 's',
|
||||
null to 0.1,
|
||||
"v" to arrayOf(1L, 2L, 3L)
|
||||
)
|
||||
),
|
||||
"i" to 1, "b" to 2.toByte(), "c" to 's', "d" to 0.1, "v" to arrayOf(1L, 2L, 3L))
|
||||
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), null to 's', "x" to 0.1))) // wrong name
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::foo, listOf(null to 1, null to 2.toByte(), "c" to 's', null to 0.1))) // unnamed after named
|
||||
Assert.assertNull(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(
|
||||
null to 1,
|
||||
null to 2.toByte(),
|
||||
null to 's',
|
||||
"x" to 0.1
|
||||
)
|
||||
)
|
||||
) // wrong name
|
||||
Assert.assertNull(
|
||||
tryCreateCallableMappingFromNamedArgs(
|
||||
::foo,
|
||||
listOf(
|
||||
null to 1,
|
||||
null to 2.toByte(),
|
||||
"c" to 's',
|
||||
null to 0.1
|
||||
)
|
||||
)
|
||||
) // unnamed after named
|
||||
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::notNullNumber, listOf(null to null)))
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::nullableNumber, listOf(null to null)),
|
||||
"n" to null)
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::notNullNumber, listOf(null to 42)),
|
||||
"n" to 42)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(::nullableNumber, listOf(null to null)),
|
||||
"n" to null)
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(::notNullNumber, listOf(null to 42)),
|
||||
"n" to 42)
|
||||
Assert.assertNull(tryCreateCallableMappingFromNamedArgs(::notNullNumber, listOf(null to "42")))
|
||||
|
||||
assertParamMapsEquals(tryCreateCallableMappingFromNamedArgs(::varargStrings, listOf("a", "b", "c").map { null to it }),
|
||||
"s" to arrayOf("a", "b", "c"))
|
||||
assertParamMapsEquals(
|
||||
tryCreateCallableMappingFromNamedArgs(::varargStrings, listOf("a", "b", "c").map { null to it }),
|
||||
"s" to arrayOf("a", "b", "c"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user