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.
}
}
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);
}
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());
}
Aggregations