use of com.google.template.soy.exprtree.OperatorNodes.OrOpNode in project closure-templates by google.
the class ParseExpressionTest method testParseOperators.
@Test
public void testParseOperators() throws Exception {
ExprNode expr = assertThatExpression("-11").isValidExpression();
IntegerNode negInt = (IntegerNode) expr;
assertThat(negInt.getValue()).isEqualTo(-11);
expr = assertThatExpression("not false").isValidExpression();
NotOpNode notOp = (NotOpNode) expr;
assertThat(((BooleanNode) notOp.getChild(0)).getValue()).isFalse();
expr = assertThatExpression("90 -14.75").isValidExpression();
MinusOpNode minusOp = (MinusOpNode) expr;
assertThat(((IntegerNode) minusOp.getChild(0)).getValue()).isEqualTo(90);
assertThat(((FloatNode) minusOp.getChild(1)).getValue()).isEqualTo(14.75);
expr = assertThatExpression("$a or true").isValidExpression();
OrOpNode orOp = (OrOpNode) expr;
assertThat(orOp.getChild(0).toSourceString()).isEqualTo("$a");
assertThat(((BooleanNode) orOp.getChild(1)).getValue()).isTrue();
expr = assertThatExpression("$a ?: $b ?: $c").isValidExpression();
NullCoalescingOpNode nullCoalOp0 = (NullCoalescingOpNode) expr;
assertThat(nullCoalOp0.getChild(0).toSourceString()).isEqualTo("$a");
NullCoalescingOpNode nullCoalOp1 = (NullCoalescingOpNode) nullCoalOp0.getChild(1);
assertThat(nullCoalOp1.getChild(0).toSourceString()).isEqualTo("$b");
assertThat(nullCoalOp1.getChild(1).toSourceString()).isEqualTo("$c");
expr = assertThatExpression("$a?:$b==null?0*1:0x1").isValidExpression();
NullCoalescingOpNode nullCoalOp = (NullCoalescingOpNode) expr;
assertThat(nullCoalOp.getChild(0).toSourceString()).isEqualTo("$a");
ConditionalOpNode condOp = (ConditionalOpNode) nullCoalOp.getChild(1);
assertThat(condOp.getChild(0)).isInstanceOf(EqualOpNode.class);
assertThat(condOp.getChild(1)).isInstanceOf(TimesOpNode.class);
assertThat(condOp.getChild(2)).isInstanceOf(IntegerNode.class);
}
Aggregations