Search in sources :

Example 6 with PredicateInst

use of com.squarespace.template.Instructions.PredicateInst in project template-compiler by Squarespace.

the class InstructionReprTest method testPredicateRepr.

@Test
public void testPredicateRepr() {
    CodeMaker mk = maker();
    PredicateInst p1 = mk.predicate(CorePredicates.PLURAL);
    assertEquals(p1.repr(), "{.plural?}");
    p1.getConsequent().add(mk.text("A"));
    assertEquals(p1.repr(), "{.plural?}A");
    p1.setAlternative(mk.end());
    assertEquals(p1.repr(), "{.plural?}A{.end}");
    PredicateInst p2 = mk.or();
    assertEquals(p2.repr(), "{.or}");
    p2.getConsequent().add(mk.text("B"));
    assertEquals(p2.repr(), "{.or}B");
    p2.setAlternative(mk.end());
    assertEquals(p2.repr(), "{.or}B{.end}");
    PredicateInst p3 = mk.or(CorePredicates.SINGULAR);
    assertEquals(p3.repr(), "{.or singular?}");
    p3.getConsequent().add(mk.text("C"));
    assertEquals(p3.repr(), "{.or singular?}C");
    p3.setAlternative(mk.end());
    assertEquals(p3.repr(), "{.or singular?}C{.end}");
    assertEquals(ReprEmitter.get(p3, false), "{.or singular?}");
}
Also used : PredicateInst(com.squarespace.template.Instructions.PredicateInst) IfPredicateInst(com.squarespace.template.Instructions.IfPredicateInst) Test(org.testng.annotations.Test)

Example 7 with PredicateInst

use of com.squarespace.template.Instructions.PredicateInst in project template-compiler by Squarespace.

the class InstructionReprTest method testSectionRepr.

@Test
public void testSectionRepr() {
    CodeMaker mk = maker();
    SectionInst s1 = mk.section("@");
    assertEquals(s1.repr(), "{.section @}");
    s1 = mk.section("a.b.c");
    assertEquals(s1.repr(), "{.section a.b.c}");
    s1.getConsequent().add(mk.text("A"));
    assertEquals(s1.repr(), "{.section a.b.c}A");
    PredicateInst p1 = mk.or();
    s1.setAlternative(p1);
    assertEquals(s1.repr(), "{.section a.b.c}A{.or}");
    p1.getConsequent().add(mk.text("B"));
    assertEquals(s1.repr(), "{.section a.b.c}A{.or}B");
    p1.setAlternative(mk.end());
    assertEquals(s1.repr(), "{.section a.b.c}A{.or}B{.end}");
    assertEquals(ReprEmitter.get(s1, false), "{.section a.b.c}");
}
Also used : PredicateInst(com.squarespace.template.Instructions.PredicateInst) IfPredicateInst(com.squarespace.template.Instructions.IfPredicateInst) SectionInst(com.squarespace.template.Instructions.SectionInst) Test(org.testng.annotations.Test)

Example 8 with PredicateInst

use of com.squarespace.template.Instructions.PredicateInst in project template-compiler by Squarespace.

the class InstructionEqualityTest method testPredicateEquals.

@Test
public void testPredicateEquals() throws CodeSyntaxException {
    CodeMaker mk = maker();
    PredicateInst p1 = mk.predicate(PLURAL);
    PredicateInst p2 = mk.predicate(PLURAL);
    assertNotEquals(p1, mk.predicate(SINGULAR));
    assertEquals(p1, p2);
    assertFalse(p1.equals(null));
    assertNotEquals(p1, mk.predicate(PLURAL, mk.args(" foo")));
    testBlockEquals(p1, p2);
    PredicateInst p3 = mk.predicate(PLURAL, mk.args(" a b"));
    PredicateInst p4 = mk.predicate(PLURAL, mk.args(" a b"));
    assertEquals(p3, p4);
}
Also used : PredicateInst(com.squarespace.template.Instructions.PredicateInst) IfPredicateInst(com.squarespace.template.Instructions.IfPredicateInst) Test(org.testng.annotations.Test)

Aggregations

PredicateInst (com.squarespace.template.Instructions.PredicateInst)8 IfPredicateInst (com.squarespace.template.Instructions.IfPredicateInst)7 SectionInst (com.squarespace.template.Instructions.SectionInst)3 Test (org.testng.annotations.Test)3 BindVarInst (com.squarespace.template.Instructions.BindVarInst)2 EvalInst (com.squarespace.template.Instructions.EvalInst)2 IfInst (com.squarespace.template.Instructions.IfInst)2 IncludeInst (com.squarespace.template.Instructions.IncludeInst)2 InjectInst (com.squarespace.template.Instructions.InjectInst)2 RepeatedInst (com.squarespace.template.Instructions.RepeatedInst)2 TextInst (com.squarespace.template.Instructions.TextInst)2 VariableInst (com.squarespace.template.Instructions.VariableInst)2 AlternatesWithInst (com.squarespace.template.Instructions.AlternatesWithInst)1 CommentInst (com.squarespace.template.Instructions.CommentInst)1 CtxVarInst (com.squarespace.template.Instructions.CtxVarInst)1 MacroInst (com.squarespace.template.Instructions.MacroInst)1 RootInst (com.squarespace.template.Instructions.RootInst)1 ReprEmitter.emitVariables (com.squarespace.template.ReprEmitter.emitVariables)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1