Search in sources :

Example 26 with RootInst

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

the class CodeExecuteTest method testVariableTypes.

@Test
public void testVariableTypes() throws CodeException {
    RootInst root = builder().var("@").eof().build();
    String value = "12345678900000000.1234567890000000";
    DecimalNode node = new DecimalNode(new BigDecimal(value));
    assertContext(execute(node, root), value);
    value = "123.0";
    node = new DecimalNode(new BigDecimal(value));
    assertContext(execute(node, root), value);
}
Also used : RootInst(com.squarespace.template.Instructions.RootInst) DecimalNode(com.fasterxml.jackson.databind.node.DecimalNode) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 27 with RootInst

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

the class CodeExecuteTest method testRepeat.

@Test
public void testRepeat() throws CodeException {
    String expected = "Hi, Joe! Hi, Bob! ";
    RootInst root = builder().repeated("@").text("Hi, ").var("foo").text("! ").end().eof().build();
    assertContext(execute("[{\"foo\": \"Joe\"},{\"foo\": \"Bob\"}]", root), expected);
}
Also used : RootInst(com.squarespace.template.Instructions.RootInst) Test(org.testng.annotations.Test)

Example 28 with RootInst

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

the class CodeExecuteTest method testLiterals.

@Test
public void testLiterals() throws CodeException {
    RootInst root = builder().metaLeft().space().tab().newline().metaRight().eof().build();
    assertContext(execute("{}", root), "{ \t\n}");
}
Also used : RootInst(com.squarespace.template.Instructions.RootInst) Test(org.testng.annotations.Test)

Example 29 with RootInst

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

the class CodeValidityTest method testAlternatesWithSectionOr.

@Test
public void testAlternatesWithSectionOr() throws CodeException {
    CodeBuilder cb = builder().repeated("a").alternatesWith().section("@").var("@").end();
    RootInst root = cb.or().text("x").end().eof().build();
    assertContext(execute("{\"a\": [1,2,3]}", root), "12");
    assertContext(execute("{}", root), "x");
}
Also used : RootInst(com.squarespace.template.Instructions.RootInst) Test(org.testng.annotations.Test)

Example 30 with RootInst

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

the class CodeValidityTest method testRepeatedScope.

@Test
public void testRepeatedScope() throws CodeException {
    RootInst root = builder().repeated("a").var("@index").or().var("b").end().eof().build();
    assertContext(execute("{\"a\": [0, 0], \"b\": \"B\"}", root), "12");
    assertContext(execute("{\"a\": null, \"b\": \"B\"}", root), "B");
}
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