use of com.squarespace.template.CodeSyntaxException in project template-compiler by Squarespace.
the class CorePredicatesTest method testJsonPredicateVariable.
@Test
public void testJsonPredicateVariable() throws CodeException {
Context ctx = context("{\"number\": 1, \"foo\": {\"bar\": 1}}");
ctx.pushSection(new String[] { "foo", "bar" });
assertTrue(EQUAL, ctx, maker().args(" number"));
String template = "{.repeated section nums}{.equal? @index 2}{@}{.end}{.end}";
JsonNode json = json("{\"nums\": [10, 20, 30]}");
ctx = execute(template, json);
assertEquals(ctx.buffer().toString(), "20");
// Ensure that invalid arguments are caught and proper error raised.
template = "{.equal? 1 -}#{.end}";
try {
execute("{.equal? 1 .}#{.end}", json("{}"));
Assert.fail("Expected CodeSyntaxException PREDICATE_ARGS_INVALID to be thrown");
} catch (CodeSyntaxException e) {
assertEquals(e.getErrorInfo().getType(), SyntaxErrorType.PREDICATE_ARGS_INVALID);
}
}
Aggregations