TemplateTokenizer tokenizer = new TemplateTokenizer(ParserTest.class.getResourceAsStream("complex.html"));
TemplateParser parser = new TemplateParser(tokenizer);
Map<String, Object> p = new DefaultTemplateBindings();
p.put("a", "AAA");
p.put("b", "BBB");
TemplateDocument t = parser.parse();
assertNotNull(t);
Attribute a = t.locateTag("/div").getAttribute("id");
assertTrue(a instanceof ComplexAttribute);
ComplexAttribute c = (ComplexAttribute) a;
assertEquals(4, c.getFragments().size());
assertTrue(c.getFragments().get(0) instanceof ExpressionNode);
assertTrue(c.getFragments().get(1) instanceof StaticFragment);
assertTrue(c.getFragments().get(2) instanceof StaticFragment);
assertTrue(c.getFragments().get(3) instanceof ExpressionNode);
ExpressionNode node1 = (ExpressionNode) c.getFragments().get(0);
StaticFragment st = (StaticFragment) c.getFragments().get(1);
StaticFragment st2 = (StaticFragment) c.getFragments().get(2);
ExpressionNode node2 = (ExpressionNode) c.getFragments().get(3);
assertEquals("${a}", node1.getSource());
assertEquals(" ", st.toString());
assertEquals("and ", st2.toString());
assertEquals("${b}", node2.getSource());
StringWriter builder = new StringWriter();
FragmentList fragmentList = t.normalize();
assertEquals(5, fragmentList.size());
assertTrue(fragmentList.get(0) instanceof StaticFragment);
assertTrue(fragmentList.get(1) instanceof ExpressionNode);