use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ExprTest method testInvalidEscapes.
@Test
public void testInvalidEscapes() {
Context c = new Context(JsonUtils.decode("{}"));
assertEquals(reduce("'\\UA0000000'", c), new TextNode(" "));
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ExprTest method testStrings.
@Test
public void testStrings() {
Context c = new Context(JsonUtils.decode("{}"));
assertEquals(reduce("'bar'", c), new TextNode("bar"));
assertEquals(reduce("\"\\\"bar\\\"\"", c), new TextNode("\"bar\""));
// incomplete escapes
assertEquals(reduce("'\\", c), null);
assertEquals(reduce("'\\'", c), null);
// unterminated
assertEquals(reduce("\"\\u000000", c), null);
// single-character escapes
assertEquals(reduce("\"\\a\\b\\c\\n\\t\\r\\f\"", c), new TextNode("abc\n\t\r\f"));
// hex escapes
assertEquals(reduce("\"\\x0a\\x09\\x20\\x7d\\x22\\x27\"", c), new TextNode("\n\t }\"'"));
// ascii control code replacement
assertEquals(reduce("\"\\x00\\x01\\x02\\x19\\x18\"", c), new TextNode(" "));
// unicode escapes
assertEquals(reduce("\"\\u2019\"", c), new TextNode("\u2019"));
assertEquals(reduce("\"\\U0001f600\"", c), new TextNode("\uD83D\uDE00"));
assertEquals(reduce("\"\\U0001f600\\U0001f600\"", c), new TextNode("\uD83D\uDE00\uD83D\uDE00"));
assertEquals(reduce("\"\\u000a\\u0009\\u0020\\u007d\\u0022\\u0027\"", c), new TextNode("\n\t }\"'"));
// unicode escape out-of-range replacement
assertEquals(reduce("\"\\u0003\\u000f\\u0019\\u0021\"", c), new TextNode(" !"));
assertEquals(reduce("\"\\U00222222\"", c), new TextNode(" "));
// ascii control code replacement
assertEquals(reduce("\"\\u0000\\u0001\\u0018\\u0019\"", c), new TextNode(" "));
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ExprTest method testModulus.
@Test
public void testModulus() {
Context c = new Context(JsonUtils.decode("{}"));
assertEquals(reduce("5 % -5", c), new DoubleNode(0));
assertEquals(reduce("5 % -4", c), new DoubleNode(1));
assertEquals(reduce("5 % -3", c), new DoubleNode(2));
assertEquals(reduce("5 % -2", c), new DoubleNode(1));
assertEquals(reduce("5 % -1", c), new DoubleNode(0));
assertEquals(reduce("5 % 0", c), new DoubleNode(Double.NaN));
assertEquals(reduce("5 % 1", c), new DoubleNode(0));
assertEquals(reduce("5 % 2", c), new DoubleNode(1));
assertEquals(reduce("5 % 3", c), new DoubleNode(2));
assertEquals(reduce("5 % 4", c), new DoubleNode(1));
assertEquals(reduce("5 % 5", c), new DoubleNode(0));
assertEquals(reduce("Infinity % 10", c), new DoubleNode(Double.NaN));
assertEquals(reduce("10 % Infinity", c), new DoubleNode(10));
assertEquals(reduce("Infinity % Infinity", c), new DoubleNode(Double.NaN));
assertEquals(reduce("5 % 3.21", c), new DoubleNode(1.79));
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ExprTest method testShift.
@Test
public void testShift() {
Context c = new Context(JsonUtils.decode("{}"));
assertEquals(reduce("14 >> -1", c), new DoubleNode(0));
assertEquals(reduce("14 >> 0", c), new DoubleNode(14));
assertEquals(reduce("14 >> 1", c), new DoubleNode(7));
assertEquals(reduce("14 >> 2", c), new DoubleNode(3));
assertEquals(reduce("14 >> 3", c), new DoubleNode(1));
assertEquals(reduce("14 >> 4", c), new DoubleNode(0));
assertEquals(reduce("14 << -1", c), new DoubleNode(0));
assertEquals(reduce("14 << 0", c), new DoubleNode(14));
assertEquals(reduce("14 << 1", c), new DoubleNode(28));
assertEquals(reduce("14 << 2", c), new DoubleNode(56));
assertEquals(reduce("14 << 3", c), new DoubleNode(112));
assertEquals(reduce("14 << 4", c), new DoubleNode(224));
// non-numbers
assertEquals(reduce("\"foo\" >> 4", c), new DoubleNode(0));
assertEquals(reduce("\"foo\" << 4", c), new DoubleNode(0));
assertEquals(reduce("true << 4", c), new DoubleNode(16));
assertEquals(reduce("null << 4", c), new DoubleNode(0));
}
use of com.squarespace.template.Context in project template-compiler by Squarespace.
the class ExprTest method testEquality.
@Test
public void testEquality() {
Context c = new Context(JsonUtils.decode("{}"));
assertEquals(reduce("1 == 1", c), BooleanNode.TRUE);
assertEquals(reduce("1 == 2", c), BooleanNode.FALSE);
assertEquals(reduce("1 == NaN", c), BooleanNode.FALSE);
assertEquals(reduce("NaN == NaN", c), BooleanNode.FALSE);
assertEquals(reduce("true == 1", c), BooleanNode.TRUE);
assertEquals(reduce("false == 1", c), BooleanNode.FALSE);
assertEquals(reduce("\"1\" == 1", c), BooleanNode.TRUE);
assertEquals(reduce("1 != 1", c), BooleanNode.FALSE);
assertEquals(reduce("1 != 2", c), BooleanNode.TRUE);
assertEquals(reduce("\"1\" != 1", c), BooleanNode.FALSE);
}
Aggregations