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