32 lines
813 B
Kotlin
32 lines
813 B
Kotlin
package template.experiment1
|
|
|
|
import kotlin.template.experiment1.*
|
|
import kotlin.test.assertEquals
|
|
import kotlin.dom.toXmlString
|
|
|
|
import junit.framework.TestCase
|
|
import org.w3c.dom.Node
|
|
|
|
|
|
class HtmlTemplateTest : TestCase() {
|
|
fun testTemplate(): Unit {
|
|
val foo = "James"
|
|
val bar = "x > 1"
|
|
|
|
val format = I18nFormatter()
|
|
// Code generated by the following template expression:
|
|
//
|
|
// val actual = format.toHtml("<h1>$foo</h1> <p>hey $bar</p>")
|
|
val actual = format.toHtml{
|
|
it.text("<h1>")
|
|
it.expression(foo)
|
|
it.text("</h1> <p>hey ")
|
|
it.expression(bar)
|
|
it.text("</p>")
|
|
}
|
|
|
|
assertEquals("<h1>James</h1> <p>hey x > 1</p>", actual)
|
|
|
|
println("Generated HTML: $actual")
|
|
}
|
|
} |