Search in sources :

Example 1 with NullNode

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

the class InternalValueUtilsTest method testConvertPrimitiveDataToExpr.

@Test
public void testConvertPrimitiveDataToExpr() {
    SourceLocation location = SourceLocation.UNKNOWN;
    assertTrue(InternalValueUtils.convertPrimitiveDataToExpr(NullData.INSTANCE, location) instanceof NullNode);
    assertEquals(false, ((BooleanNode) InternalValueUtils.convertPrimitiveDataToExpr(BooleanData.FALSE, location)).getValue());
    assertEquals(26, ((IntegerNode) InternalValueUtils.convertPrimitiveDataToExpr(IntegerData.forValue(26), location)).getValue());
    assertEquals(-3.14159, ((FloatNode) InternalValueUtils.convertPrimitiveDataToExpr(FloatData.forValue(-3.14159), location)).getValue(), 0.0);
    assertEquals("boo", ((StringNode) InternalValueUtils.convertPrimitiveDataToExpr(StringData.forValue("boo"), location)).getValue());
    try {
        InternalValueUtils.convertPrimitiveDataToExpr(UndefinedData.INSTANCE, location);
        fail();
    } catch (IllegalArgumentException iae) {
    // Test passes.
    }
}
Also used : SourceLocation(com.google.template.soy.base.SourceLocation) NullNode(com.google.template.soy.exprtree.NullNode) Test(org.junit.Test)

Example 2 with NullNode

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

the class VeLogInstrumentationVisitor method visitVeLogNode.

/**
 * Adds data-soylog attribute to the top-level DOM node in this {velog} block.
 */
@Override
protected void visitVeLogNode(VeLogNode node) {
    // VeLogValidationPass enforces that the first child is a open tag. We can safely cast it here.
    HtmlOpenTagNode tag = (HtmlOpenTagNode) node.getChild(0);
    SourceLocation insertionLocation = tag.getSourceLocation().getEndPoint().offset(0, tag.isSelfClosing() ? -2 : -1).asLocation(tag.getSourceLocation().getFilePath());
    FunctionNode funcNode = new FunctionNode(VeLogFunction.INSTANCE, insertionLocation);
    funcNode.addChild(new IntegerNode(node.getLoggingId(), insertionLocation));
    funcNode.addChild(node.getConfigExpression() == null ? new NullNode(insertionLocation) : node.getConfigExpression().copy(new CopyState()));
    if (node.getLogonlyExpression() != null) {
        funcNode.addChild(node.getLogonlyExpression().copy(new CopyState()));
    }
    PrintNode attributeNode = new PrintNode(nodeIdGen.genId(), insertionLocation, /* isImplicit= */
    true, /* expr= */
    funcNode, /* attributes= */
    ImmutableList.of(), ErrorReporter.exploding());
    tag.addChild(attributeNode);
    visitChildren(node);
}
Also used : SourceLocation(com.google.template.soy.base.SourceLocation) IntegerNode(com.google.template.soy.exprtree.IntegerNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) CopyState(com.google.template.soy.basetree.CopyState) PrintNode(com.google.template.soy.soytree.PrintNode) NullNode(com.google.template.soy.exprtree.NullNode) HtmlOpenTagNode(com.google.template.soy.soytree.HtmlOpenTagNode)

Example 3 with NullNode

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

the class InternalValueUtilsTest method testConvertPrimitiveExprToData.

@Test
public void testConvertPrimitiveExprToData() {
    assertTrue(InternalValueUtils.convertPrimitiveExprToData(new NullNode(SourceLocation.UNKNOWN)) instanceof NullData);
    assertTrue(InternalValueUtils.convertPrimitiveExprToData(new BooleanNode(true, SourceLocation.UNKNOWN)).booleanValue());
    assertEquals(-1, InternalValueUtils.convertPrimitiveExprToData(new IntegerNode(-1, SourceLocation.UNKNOWN)).integerValue());
    assertEquals(6.02e23, InternalValueUtils.convertPrimitiveExprToData(new FloatNode(6.02e23, SourceLocation.UNKNOWN)).floatValue(), 0.0);
    assertEquals("foo", InternalValueUtils.convertPrimitiveExprToData(new StringNode("foo", QuoteStyle.SINGLE, SourceLocation.UNKNOWN)).stringValue());
}
Also used : NullData(com.google.template.soy.data.restricted.NullData) IntegerNode(com.google.template.soy.exprtree.IntegerNode) FloatNode(com.google.template.soy.exprtree.FloatNode) StringNode(com.google.template.soy.exprtree.StringNode) BooleanNode(com.google.template.soy.exprtree.BooleanNode) NullNode(com.google.template.soy.exprtree.NullNode) Test(org.junit.Test)

Aggregations

NullNode (com.google.template.soy.exprtree.NullNode)3 SourceLocation (com.google.template.soy.base.SourceLocation)2 IntegerNode (com.google.template.soy.exprtree.IntegerNode)2 Test (org.junit.Test)2 CopyState (com.google.template.soy.basetree.CopyState)1 NullData (com.google.template.soy.data.restricted.NullData)1 BooleanNode (com.google.template.soy.exprtree.BooleanNode)1 FloatNode (com.google.template.soy.exprtree.FloatNode)1 FunctionNode (com.google.template.soy.exprtree.FunctionNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 HtmlOpenTagNode (com.google.template.soy.soytree.HtmlOpenTagNode)1 PrintNode (com.google.template.soy.soytree.PrintNode)1