public void testWithoutCssRenamingMap() { TemplateNode template = (TemplateNode) SharedTestUtils.getNode(SharedTestUtils.parseSoyFiles(TEST_FILE_CONTENT)); // Before. assertEquals(9, template.numChildren()); CssNode cn1 = (CssNode) template.getChild(1); assertEquals("AAA", cn1.getSelectorText()); CssNode cn7 = (CssNode) template.getChild(7); assertEquals("$goo", cn7.getComponentNameText()); assertEquals("BBB", cn7.getSelectorText()); (new RenameCssVisitor(null)).exec(template); (new CombineConsecutiveRawTextNodesVisitor()).exec(template); // After. assertEquals(5, template.numChildren()); RawTextNode rtn0 = (RawTextNode) template.getChild(0); assertEquals("<div class=\"AAA ", rtn0.getRawText()); PrintNode pn1 = (PrintNode) template.getChild(1); assertEquals("$goo", pn1.getExprText()); RawTextNode rtn2 = (RawTextNode) template.getChild(2); assertEquals("-AAA BBB ", rtn2.getRawText()); PrintNode pn3 = (PrintNode) template.getChild(3); assertEquals("$goo", pn3.getExprText()); RawTextNode rtn4 = (RawTextNode) template.getChild(4); assertEquals("-BBB\">", rtn4.getRawText()); }
public void testWithCssRenamingMap() { TemplateNode template = (TemplateNode) SharedTestUtils.getNode(SharedTestUtils.parseSoyFiles(TEST_FILE_CONTENT)); // Before. assertEquals(9, template.numChildren()); CssNode cn1 = (CssNode) template.getChild(1); assertEquals("AAA", cn1.getSelectorText()); CssNode cn7 = (CssNode) template.getChild(7); assertEquals("$goo", cn7.getComponentNameText()); assertEquals("BBB", cn7.getSelectorText()); // Use a CSS renaming map that only renames 'AAA'. SoyCssRenamingMap cssRenamingMap = new SoyCssRenamingMap() { @Override public String get(String key) { return key.equals("AAA") ? "XXX" : null; } }; (new RenameCssVisitor(cssRenamingMap)).exec(template); (new CombineConsecutiveRawTextNodesVisitor()).exec(template); // After. assertEquals(5, template.numChildren()); RawTextNode rtn0 = (RawTextNode) template.getChild(0); assertEquals("<div class=\"XXX ", rtn0.getRawText()); PrintNode pn1 = (PrintNode) template.getChild(1); assertEquals("$goo", pn1.getExprText()); RawTextNode rtn2 = (RawTextNode) template.getChild(2); assertEquals("-XXX BBB ", rtn2.getRawText()); PrintNode pn3 = (PrintNode) template.getChild(3); assertEquals("$goo", pn3.getExprText()); RawTextNode rtn4 = (RawTextNode) template.getChild(4); assertEquals("-BBB\">", rtn4.getRawText()); }