Add Lyng string interpolation with docs/tests and refresh changelog

This commit is contained in:
sergeych committed 2026-03-25 18:43:23 +03:00
1 parent 3b83439788
commit 3d8bfe8863
9 files changed
+497 -178

No files matched your search

@@ -114,7 +114,7 @@ class ObjectExpressionTest {
eval("""
val x = object { }
val name = ((x::class as Class).className as String)
assert(name.startsWith("${'$'}Anon_"))
assert(name.startsWith("\${'$'}Anon_"))
""".trimIndent())
}
}
+37 -20
View File
@@ -4194,26 +4194,43 @@ class ScriptTest {
// }
// @Ignore
// @Test
// fun interpolationTest() = runTest {
// eval($$$"""
//
// val foo = "bar"
// val buzz = ["foo", "bar"]
//
// // 1. simple interpolation
// assertEquals( "bar", "$foo" )
// assertEquals( "bar", "${foo}" )
//
// // 2. escaping the dollar sign
// assertEquals( "$", "\$foo"[0] )
// assertEquals( "foo, "\$foo"[1..] )
//
// // 3. interpolation with expression
// assertEquals( "foo!. bar?", "${buzz[0]+"!"}. ${buzz[1]+"?"}" )
// """.trimIndent())
// }
@Test
fun interpolationTest() = runTest {
val d = '$'
eval(
"""
val foo = "bar"
val buzz = ["foo", "bar"]
// 1. simple interpolation
assertEquals("bar", "${d}foo")
assertEquals("bar", "${d}{foo}")
// 2. escaping / literal dollar forms
assertEquals("${d}${d}foo", "\${d}foo")
assertEquals("${d}${d}foo", "${d}${d}foo")
assertEquals("\\bar", "\\${d}foo")
// 3. interpolation with expression
assertEquals("foo!. bar?", "${d}{buzz[0] + "!"}. ${d}{buzz[1] + "?"}")
""".trimIndent()
)
}
@Test
fun interpolationCanBeDisabledByFeatureComment() = runTest {
val d = '$'
eval(
"""
// feature: interpolation: off
val name = "lyng"
assertEquals("hello, ${d}name!", "hello, ${d}name!")
assertEquals("${d}{name}", "${d}{name}")
assertEquals("${d}${d}name", "${d}${d}name")
assertEquals("\\${d}name", "\\${d}name")
""".trimIndent()
)
}
@Test
fun testInlineArrayLiteral() = runTest {