Search in sources :

Example 41 with RootInst

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

the class HardSoftCodeLimiterTest method testSoftLimit.

@Test
public void testSoftLimit() throws CodeException {
    TestHandler handler = new TestHandler(Limit.SOFT, 6);
    CodeLimiter limiter = HardSoftCodeLimiter.builder().setSoftLimit(5).setResolution(1).setHandler(handler).build();
    JsonNode node = JsonUtils.decode("[0,1,2,3,4,5,6,7,8,9]");
    Context ctx = new Context(node);
    ctx.setCodeLimiter(limiter);
    RootInst root = builder().repeated("@").var("@").end().eof().build();
    ctx.execute(root);
    assertTrue(handler.wasCalled());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) RootInst(com.squarespace.template.Instructions.RootInst) Test(org.testng.annotations.Test)

Example 42 with RootInst

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

the class InstructionEqualityTest method testRootEquals.

@Test
public void testRootEquals() throws CodeSyntaxException {
    CodeMaker mk = maker();
    RootInst r1 = mk.root();
    RootInst r2 = mk.root();
    assertEquals(r1, r2);
    assertFalse(r1.equals(null));
    assertNotEquals(r1, mk.end());
    assertNotEquals(r1, mk.section("foo"));
    r1.getConsequent().add(mk.text("foo"));
    assertNotEquals(r1, r2);
    assertNotEquals(r1, mk.end());
    r2.getConsequent().add(mk.text("foo"));
    assertEquals(r1, r2);
    r2.getConsequent().add(mk.end());
    assertNotEquals(r1, r2);
}
Also used : RootInst(com.squarespace.template.Instructions.RootInst) Test(org.testng.annotations.Test)

Aggregations

RootInst (com.squarespace.template.Instructions.RootInst)42 Test (org.testng.annotations.Test)41 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)1 AlternatesWithInst (com.squarespace.template.Instructions.AlternatesWithInst)1 IfInst (com.squarespace.template.Instructions.IfInst)1 IfPredicateInst (com.squarespace.template.Instructions.IfPredicateInst)1 PredicateInst (com.squarespace.template.Instructions.PredicateInst)1 RepeatedInst (com.squarespace.template.Instructions.RepeatedInst)1 SectionInst (com.squarespace.template.Instructions.SectionInst)1 TextInst (com.squarespace.template.Instructions.TextInst)1 VariableInst (com.squarespace.template.Instructions.VariableInst)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1