Package com.google.template.soy.soytree

Examples of com.google.template.soy.soytree.SwitchNode


        "  {/switch}\n";

    List<StandaloneNode> nodes = parseTemplateBody(templateBody);
    assertEquals(1, nodes.size());

    SwitchNode sn = (SwitchNode) nodes.get(0);
    assertEquals("$boo", sn.getExpr().toSourceString());
    assertTrue(sn.getExpr().getChild(0) instanceof DataRefNode);
    assertEquals(4, sn.numChildren());

    SwitchCaseNode scn0 = (SwitchCaseNode) sn.getChild(0);
    assertEquals("0", scn0.getExprListText());
    assertEquals(1, scn0.getExprList().size());
    assertTrue(scn0.getExprList().get(0).getChild(0) instanceof IntegerNode);

    SwitchCaseNode scn1 = (SwitchCaseNode) sn.getChild(1);
    assertEquals("$foo.goo", scn1.getExprListText());
    assertEquals(1, scn1.getExprList().size());
    assertTrue(scn1.getExprList().get(0).getChild(0) instanceof DataRefNode);

    SwitchCaseNode scn2 = (SwitchCaseNode) sn.getChild(2);
    assertEquals("-1, 1, $moo", scn2.getExprListText());
    assertEquals(3, scn2.getExprList().size());
    assertTrue(scn2.getExprList().get(0).getChild(0) instanceof NegativeOpNode);
    assertTrue(scn2.getExprList().get(1).getChild(0) instanceof IntegerNode);
    assertTrue(scn2.getExprList().get(2).getChild(0) instanceof DataRefNode);
    assertEquals("Bluh", ((RawTextNode) scn2.getChild(0)).getRawText());

    assertEquals(
        "Bloh", ((RawTextNode) ((SwitchDefaultNode) sn.getChild(3)).getChild(0)).getRawText());

    assertEquals(
        "{switch $boo}{case 0}Blah{case $foo.goo}Bleh{case -1, 1, $moo}Bluh{default}Bloh{/switch}",
        sn.toSourceString());
  }
View Full Code Here

TOP

Related Classes of com.google.template.soy.soytree.SwitchNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.