@Test public void renderTest() throws RecognitionException { String[][] tests = { {"{% assign name = 'freestyle' %}{{ name }}", "freestyle"}, {"{% assign age = 42 %}{{ age }}", "42"}, }; for (String[] test : tests) { Template template = Template.parse(test[0]); String rendered = String.valueOf(template.render()); assertThat(rendered, is(test[1])); } String json = "{\"values\":[\"A\", [\"B1\", \"B2\"], \"C\"]}"; assertThat( Template.parse("{% assign foo = values %}.{{ foo[1][1] }}.").render(json), is(".B2.")); json = "{\"values\":[\"A\", {\"bar\":{\"xyz\":[\"B1\", \"ok\"]}}, \"C\"]}"; assertThat( Template.parse("{% assign foo = values %}.{{ foo[1].bar.xyz[1] }}.").render(json), is(".ok.")); }
@Test public void applyTest() throws RecognitionException { String[][] tests = { {"{{ '' | replace_first:'a', 'A' }}", ""}, {"{{ nil | replace_first:'a', 'A' }}", ""}, {"{{ 'aabbabab' | replace_first:'ab', 'A' }}", "aAbabab"}, {"{{ 'ababab' | replace_first:'a', 'A' }}", "Ababab"}, }; for (String[] test : tests) { Template template = Template.parse(test[0]); String rendered = String.valueOf(template.render()); assertThat(rendered, is(test[1])); } }