Scripting: support scripts starting with UTF-8 BOM

#KT-54705 fixed
This commit is contained in:
Ilya Chernikov
2023-01-04 17:48:14 +01:00
parent 989c1ec64d
commit 6c035bb5f4
4 changed files with 27 additions and 2 deletions
@@ -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()
@@ -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")