Scripting: support scripts starting with UTF-8 BOM
#KT-54705 fixed
This commit is contained in:
+9
@@ -154,6 +154,13 @@ class MainKtsIT {
|
||||
listOf("""\{"firstName":"James","lastName":"Bond"\}""", "User\\(firstName=James, lastName=Bond\\)")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUtf8Bom() {
|
||||
val scriptPath = "$TEST_DATA_ROOT/utf8bom.main.kts"
|
||||
Assert.assertTrue("Expect file '$scriptPath' to start with UTF-8 BOM", File(scriptPath).readText().startsWith(UTF8_BOM))
|
||||
runWithKotlincAndMainKts(scriptPath, listOf("Hello world"))
|
||||
}
|
||||
}
|
||||
|
||||
fun runWithKotlincAndMainKts(
|
||||
@@ -204,3 +211,5 @@ fun runWithK2JVMCompilerAndMainKts(
|
||||
}
|
||||
}
|
||||
|
||||
internal const val UTF8_BOM = 0xfeff.toChar().toString()
|
||||
|
||||
|
||||
+8
@@ -266,6 +266,14 @@ class MainKtsTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUtf8Bom() {
|
||||
val scriptPath = "$TEST_DATA_ROOT/utf8bom.main.kts"
|
||||
Assert.assertTrue("Expect file '$scriptPath' to start with UTF-8 BOM", File(scriptPath).readText().startsWith(UTF8_BOM))
|
||||
val res = evalFile(File(scriptPath))
|
||||
assertSucceeded(res)
|
||||
}
|
||||
|
||||
private fun assertSucceeded(res: ResultWithDiagnostics<EvaluationResult>) {
|
||||
Assert.assertTrue(
|
||||
"test failed:\n ${res.reports.joinToString("\n ") { it.severity.name + ": " + it.message + if (it.exception == null) "" else ": ${it.exception}" }}",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
println("Hello world")
|
||||
Reference in New Issue
Block a user