use of com.squarespace.template.Instructions.RootInst in project template-compiler by Squarespace.
the class CodeValidityTest method testSectionScope.
@Test
public void testSectionScope() throws CodeException {
RootInst root = builder().section("a").var("a").or().var("b").end().eof().build();
assertContext(execute("{\"a\": 1, \"b\": \"B\"}", root), "1");
assertContext(execute("{\"a\": 0, \"b\": \"B\"}", root), "B");
}
use of com.squarespace.template.Instructions.RootInst in project template-compiler by Squarespace.
the class CodeValidityTest method testRepeatedOr.
@Test
public void testRepeatedOr() throws CodeException {
String jsonData = "{\"a\": [0, 0, 0]}";
RootInst root = builder().repeated("a").var("@").alternatesWith().text("-").or().text("X").end().eof().build();
assertContext(execute(jsonData, root), "0-0-0");
jsonData = "{\"b\": [0, 0, 0]}";
assertContext(execute(jsonData, root), "X");
}
use of com.squarespace.template.Instructions.RootInst in project template-compiler by Squarespace.
the class CodeValidityTest method testAlternatesWith.
/**
* Sort of confusing to add sections to ALTERNATES_WITH block, since we're always pointing to the
* next element in the array when that block is executed. Typical uses of ALTERNATES_WITH just output
* static text, but nesting things inside those blocks is possible.
*/
@Test
public void testAlternatesWith() throws CodeException {
RootInst root = builder().repeated("a").alternatesWith().section("b").var("@").end().end().eof().build();
String json = "{\"a\": [{\"b\": 1}, {\"b\": 2}, {\"b\": 3}, {\"b\": 4}]}";
assertContext(execute(json, root), "123");
}
use of com.squarespace.template.Instructions.RootInst in project template-compiler by Squarespace.
the class CodeValidityTest method testVariables.
@Test
public void testVariables() throws CodeException {
RootInst root = builder().var("foo").var("bar").eof().build();
assertContext(execute("{\"foo\": 1, \"bar\": 2}", root), "12");
}
use of com.squarespace.template.Instructions.RootInst in project template-compiler by Squarespace.
the class CodeValidityTest method testText.
@Test
public void testText() throws CodeException {
RootInst root = builder().text("foo").text("bar").eof().build();
assertContext(execute("{}", root), "foobar");
root = builder().eof().build();
assertContext(execute("{}", root), "");
}
Aggregations