From f167d3e35ea75c36e274b6e1b58ae0f85c9de5a1 Mon Sep 17 00:00:00 2001 From: Charlie Croom Date: Wed, 22 Mar 2017 12:49:55 -0700 Subject: [PATCH] Add test cases for scala handler dot notation with classes --- .../twitter/mustache/ObjectHandlerTest.scala | 32 +++++++++++++++++++ .../twitter/mustache/ObjectHandlerTest.scala | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/scala-extensions/scala-extensions-2.10/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala b/scala-extensions/scala-extensions-2.10/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala index a556d7272..9def7ff1a 100644 --- a/scala-extensions/scala-extensions-2.10/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala +++ b/scala-extensions/scala-extensions-2.10/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala @@ -21,6 +21,38 @@ class ObjectHandlerTest { Assert.assertEquals("fred", sw.toString()) } + @Test + def testClass() { + val mf = new DefaultMustacheFactory() + mf.setObjectHandler(new ScalaObjectHandler) + val m = mf.compile( + new StringReader("{{#map}}{{test}}{{test2}}{{/map}}"), + "helloworld" + ) + case class TestClass( + test: String + ) + val sw = new StringWriter + val w = m.execute(sw, Map( "map" -> TestClass("fred") ) ).close() + Assert.assertEquals("fred", sw.toString()) + } + + @Test + def testClassDot() { + val mf = new DefaultMustacheFactory() + mf.setObjectHandler(new ScalaObjectHandler) + val m = mf.compile( + new StringReader("{{map.test}}"), + "helloworld" + ) + case class TestClass( + test: String + ) + val sw = new StringWriter + val w = m.execute(sw, Map( "map" -> TestClass("fred") ) ).close() + Assert.assertEquals("fred", sw.toString()) + } + @Test def testTwitterHandler() { val pool = Executors.newCachedThreadPool() diff --git a/scala-extensions/scala-extensions-2.11/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala b/scala-extensions/scala-extensions-2.11/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala index e18bc1d9e..11714d643 100644 --- a/scala-extensions/scala-extensions-2.11/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala +++ b/scala-extensions/scala-extensions-2.11/src/test/scala/com/twitter/mustache/ObjectHandlerTest.scala @@ -21,6 +21,38 @@ class ObjectHandlerTest { Assert.assertEquals("fred", sw.toString()) } + @Test + def testClass() { + val mf = new DefaultMustacheFactory() + mf.setObjectHandler(new ScalaObjectHandler) + val m = mf.compile( + new StringReader("{{#map}}{{test}}{{test2}}{{/map}}"), + "helloworld" + ) + case class TestClass( + test: String + ) + val sw = new StringWriter + val w = m.execute(sw, Map( "map" -> TestClass("fred") ) ).close() + Assert.assertEquals("fred", sw.toString()) + } + + @Test + def testClassDot() { + val mf = new DefaultMustacheFactory() + mf.setObjectHandler(new ScalaObjectHandler) + val m = mf.compile( + new StringReader("{{map.test}}"), + "helloworld" + ) + case class TestClass( + test: String + ) + val sw = new StringWriter + val w = m.execute(sw, Map( "map" -> TestClass("fred") ) ).close() + Assert.assertEquals("fred", sw.toString()) + } + @Test def testScalaHandler() { val pool = Executors.newCachedThreadPool()