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?}");
}
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}");
}
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);
}
Aggregations