initial spike to show how KT-1565 might look for auto-escaping of HTML/XML/JSON/JDBC/URLs etc
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package test.template
|
||||
|
||||
import junit.framework.TestCase
|
||||
import kotlin.template.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class HtmlTemplateTest : TestCase() {
|
||||
fun testTemplate(): Unit {
|
||||
val foo = "James"
|
||||
val bar = "x > 1"
|
||||
|
||||
// Code generated by the following template expression:
|
||||
//
|
||||
// val actual = [Html]"<h1>$foo</h1> <p>hey $bar</p>"
|
||||
val builder = HtmlTemplate(array("<h1>", "</h1> <p>hey ", "</p>")).builder()
|
||||
builder.expression(foo)
|
||||
builder.expression(bar)
|
||||
val actual = builder.build()
|
||||
|
||||
assertEquals("<h1>James</h1> <p>hey x > 1</p>", actual)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package test.template
|
||||
|
||||
import junit.framework.TestCase
|
||||
import kotlin.template.StringTemplate
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class StringTemplateTest : TestCase() {
|
||||
fun testTemplate(): Unit {
|
||||
val name = "James"
|
||||
|
||||
// Code generated by the following template expression:
|
||||
//
|
||||
// val actual = "hello $name!"
|
||||
val builder = StringTemplate(array("hello ", "!")).builder()
|
||||
builder.expression(name)
|
||||
val actual = builder.build()
|
||||
|
||||
assertEquals("hello James!", actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user