use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrLenFunctionTest method testComputeForJava_containsString.
@Test
public void testComputeForJava_containsString() {
StrLenFunction strLen = new StrLenFunction();
SoyValue arg0 = StringData.forValue("foobarfoo");
assertThat(strLen.computeForJava(ImmutableList.of(arg0))).isEqualTo(IntegerData.forValue(9));
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class BidiDirAttrFunctionTest method testComputeForJava.
@Test
public void testComputeForJava() {
SoyValue text = StringData.EMPTY_STRING;
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = StringData.forValue("a");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = StringData.forValue("\u05E0");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"rtl\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("\u05E0");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"rtl\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.RTL);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"rtl\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.LTR);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.NEUTRAL);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = StringData.EMPTY_STRING;
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = StringData.forValue("\u05E0");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = StringData.forValue("a");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"ltr\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("a");
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"ltr\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("a", Dir.LTR);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("dir=\"ltr\"", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("a", Dir.RTL);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
text = SanitizedContents.unsanitizedText("a", Dir.NEUTRAL);
assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(UnsafeSanitizedContentOrdainer.ordainAsSafe("", SanitizedContent.ContentKind.ATTRIBUTES));
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class SimplifyExprVisitor method visitAndOpNode.
// -----------------------------------------------------------------------------------------------
// Implementations for operators.
@Override
protected void visitAndOpNode(AndOpNode node) {
// Recurse.
visitChildren(node);
// Can simplify if either child is constant. We assume no side-effects.
SoyValue operand0 = getConstantOrNull(node.getChild(0));
if (operand0 != null) {
ExprNode replacementNode = operand0.coerceToBoolean() ? node.getChild(1) : node.getChild(0);
node.getParent().replaceChild(node, replacementNode);
}
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class SimplifyExprVisitor method visitOrOpNode.
@Override
protected void visitOrOpNode(OrOpNode node) {
// Recurse.
visitChildren(node);
// Can simplify if either child is constant. We assume no side-effects.
SoyValue operand0 = getConstantOrNull(node.getChild(0));
if (operand0 != null) {
ExprNode replacementNode = operand0.coerceToBoolean() ? node.getChild(0) : node.getChild(1);
node.getParent().replaceChild(node, replacementNode);
}
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class SimplifyExprVisitor method visitConditionalOpNode.
@Override
protected void visitConditionalOpNode(ConditionalOpNode node) {
// Recurse.
visitChildren(node);
// Can simplify if operand0 is constant. We assume no side-effects.
SoyValue operand0 = getConstantOrNull(node.getChild(0));
if (operand0 == null) {
// cannot simplify
return;
}
ExprNode replacementNode = operand0.coerceToBoolean() ? node.getChild(1) : node.getChild(2);
node.getParent().replaceChild(node, replacementNode);
}
Aggregations