refactored the template experiment1 implementation to add i18n support of numbers & dates
This commit is contained in:
@@ -13,10 +13,11 @@ class HtmlTemplateTest : TestCase() {
|
||||
val foo = "James"
|
||||
val bar = "x > 1"
|
||||
|
||||
val format = I18nFormatter()
|
||||
// Code generated by the following template expression:
|
||||
//
|
||||
// val actual = toHtml("<h1>$foo</h1> <p>hey $bar</p>")
|
||||
val actual = toHtml{
|
||||
// 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 ")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package template.experiment1
|
||||
|
||||
import kotlin.template.experiment1.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
import junit.framework.TestCase
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class I18nTemplateTest : TestCase() {
|
||||
fun testDefaultLocale() : Unit {
|
||||
format(I18nFormatter())
|
||||
}
|
||||
|
||||
fun testFrance() : Unit {
|
||||
format(I18nFormatter(Locale.FRANCE.sure()))
|
||||
}
|
||||
|
||||
fun testGermany() : Unit {
|
||||
format(I18nFormatter(Locale.GERMANY.sure()))
|
||||
}
|
||||
|
||||
fun format(format: I18nFormatter): Unit {
|
||||
val name = "James"
|
||||
// TODO currently numbers cause: java.lang.ClassNotFoundException: jet.Number
|
||||
//val price: Double = 1.99
|
||||
val now = Date()
|
||||
|
||||
|
||||
// Code generated by the following template expression:
|
||||
//
|
||||
// val actual = format.toI18n("hello $name!")
|
||||
val actual = format.toString{
|
||||
it.text("hello ")
|
||||
it.expression(name)
|
||||
/*
|
||||
it.text(" price ")
|
||||
it.expression(price)
|
||||
*/
|
||||
it.text(" date ")
|
||||
it.expression(now)
|
||||
}
|
||||
|
||||
println("Got text: $actual")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user