Search in sources :

Example 1 with NegativeOpNode

use of com.google.template.soy.exprtree.OperatorNodes.NegativeOpNode in project closure-templates by google.

the class AbstractOperatorNodeTest method testToSourceString1.

@Test
public void testToSourceString1() {
    // Test expression: $x - -$x - (-($x - $x) - $x)
    // 
    // The expression tree looks like this:
    // [MinusOpNode] n0
    // [MinusOpNode] n1
    // [VarRefNode] $x
    // [NegativeOpNode] n3
    // [VarRefNode] $x
    // [MinusOpNode] n2
    // [NegativeOpNode] n4
    // [MinusOpNode] n5
    // [VarRefNode] $x
    // [VarRefNode] $x
    // [VarRefNode] $x
    // Root n0.
    MinusOpNode n0 = new MinusOpNode(X);
    // Children of n0.
    MinusOpNode n1 = new MinusOpNode(X);
    MinusOpNode n2 = new MinusOpNode(X);
    n0.addChild(n1);
    n0.addChild(n2);
    // Children of n1.
    NegativeOpNode n3 = new NegativeOpNode(X);
    n1.addChild(x);
    n1.addChild(n3);
    // Child of n3.
    n3.addChild(x.copy(new CopyState()));
    // Children of n2.
    NegativeOpNode n4 = new NegativeOpNode(X);
    n2.addChild(n4);
    n2.addChild(x.copy(new CopyState()));
    // Child of n4.
    MinusOpNode n5 = new MinusOpNode(X);
    n4.addChild(n5);
    // Children of n5.
    n5.addChild(x.copy(new CopyState()));
    n5.addChild(x.copy(new CopyState()));
    assertThat(n0.toSourceString()).isEqualTo("$x - -$x - (-($x - $x) - $x)");
}
Also used : NegativeOpNode(com.google.template.soy.exprtree.OperatorNodes.NegativeOpNode) MinusOpNode(com.google.template.soy.exprtree.OperatorNodes.MinusOpNode) CopyState(com.google.template.soy.basetree.CopyState) Test(org.junit.Test)

Aggregations

CopyState (com.google.template.soy.basetree.CopyState)1 MinusOpNode (com.google.template.soy.exprtree.OperatorNodes.MinusOpNode)1 NegativeOpNode (com.google.template.soy.exprtree.OperatorNodes.NegativeOpNode)1 Test (org.junit.Test)1