use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class BidiMarkAfterFunctionTest method testComputeForJava.
@Test
public void testComputeForJava() {
SoyValue text = StringData.EMPTY_STRING;
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = StringData.forValue("a");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = StringData.forValue("\u05E0");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = SanitizedContents.unsanitizedText("a");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("a", Dir.LTR);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("a", Dir.NEUTRAL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("a", Dir.RTL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = SanitizedContents.unsanitizedText("\u05E0");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.RTL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.NEUTRAL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = SanitizedContents.unsanitizedText("\u05E0", Dir.LTR);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_LTR.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200E"));
text = StringData.EMPTY_STRING;
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = StringData.forValue("\u05E0");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = StringData.forValue("a");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
text = SanitizedContents.unsanitizedText("\u05E0");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("\u05E0", Dir.RTL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("\u05E0", Dir.NEUTRAL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.EMPTY_STRING);
text = SanitizedContents.unsanitizedText("\u05E0", Dir.LTR);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
text = SanitizedContents.unsanitizedText("a");
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
text = SanitizedContents.unsanitizedText("a", Dir.LTR);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
text = SanitizedContents.unsanitizedText("a", Dir.NEUTRAL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
text = SanitizedContents.unsanitizedText("a", Dir.RTL);
assertThat(BIDI_MARK_AFTER_FUNCTION_FOR_STATIC_RTL.computeForJava(ImmutableList.of(text))).isEqualTo(StringData.forValue("\u200F"));
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class EasyListImplTest method testListMethods.
@Test
public void testListMethods() {
StringData BLAH_0 = StringData.forValue("blah");
FloatData PI = FloatData.forValue(3.14);
SoyValue BLAH_2 = StringData.forValue("blah");
SoyEasyList list = new EasyListImpl();
assertThat(list.length()).isEqualTo(0);
assertThat(list.asJavaList()).isEmpty();
assertThat(list.asResolvedJavaList()).isEmpty();
assertThat(list.get(0)).isNull();
assertThat(list.getProvider(0)).isNull();
list.add(BLAH_0);
list.add(PI);
list.add(BLAH_2);
// At this point, list should be [BLAH_0, PI, BLAH_2].
assertThat(list.length()).isEqualTo(3);
assertThat(list.asJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
assertThat(list.asResolvedJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
assertThat(list.get(0)).isSameAs(BLAH_0);
assertThat(list.get(0)).isNotSameAs(BLAH_2);
// not same, but they compare equal
assertThat(list.get(0)).isEqualTo(BLAH_2);
assertThat(list.getProvider(1).resolve().floatValue()).isWithin(0.0).of(3.14);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class EasyListImplTest method testSoyValueMethods.
@Test
public void testSoyValueMethods() {
SoyValue val1 = new EasyListImpl();
// EasyListImpl is always truthy.
assertThat(val1.coerceToBoolean()).isTrue();
assertThat(val1.coerceToString()).isEqualTo("[]");
SoyValue val2 = new EasyListImpl();
// EasyListImpl uses object identity.
assertThat(val1.equals(val2)).isFalse();
SoyValue val3 = SoyValueConverterUtility.newList(111, true);
assertThat(val3.coerceToBoolean()).isTrue();
assertThat(val3.coerceToString()).isEqualTo("[111, true]");
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class RenderVisitor method visitPrintNode.
@Override
protected void visitPrintNode(PrintNode node) {
SoyValue result = eval(node.getExpr(), node);
if (result instanceof UndefinedData) {
throw RenderException.createWithSource("In 'print' tag, expression \"" + node.getExpr().toSourceString() + "\" evaluates to undefined.", node);
}
// Process directives.
for (PrintDirectiveNode directiveNode : node.getChildren()) {
// Evaluate directive args.
List<ExprRootNode> argsExprs = directiveNode.getArgs();
List<SoyValue> argsSoyDatas = Lists.newArrayListWithCapacity(argsExprs.size());
for (ExprRootNode argExpr : argsExprs) {
argsSoyDatas.add(eval(argExpr, directiveNode));
}
// Apply directive.
result = applyDirective(directiveNode.getPrintDirective(), result, argsSoyDatas, node);
}
append(currOutputBuf, result, node);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class RoundFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue value = args.get(0);
int numDigitsAfterPt = (args.size() == 2) ? args.get(1).integerValue() : 0;
return BasicFunctionsRuntime.round(value, numDigitsAfterPt);
}
Aggregations