use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class AbstractSoyPrintDirectiveTestCase method assertTofuOutput.
/**
* @param expectedOutput The expected result of applying directive to value with args.
* @param value The test input.
* @param directive The directive whose {@link SoyJavaPrintDirective#applyForJava} is under test.
* @param args Arguments to the Soy directive.
*/
protected void assertTofuOutput(SoyValue expectedOutput, Object value, SoyJavaPrintDirective directive, Object... args) {
ImmutableList.Builder<SoyValue> argsData = ImmutableList.builder();
for (Object arg : args) {
argsData.add(SoyValueConverter.INSTANCE.convert(arg).resolve());
}
assertThat(directive.applyForJava(SoyValueConverter.INSTANCE.convert(value).resolve(), argsData.build()).toString()).isEqualTo(expectedOutput.toString());
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class ListImplTest method testListMethods.
@Test
public void testListMethods() {
StringData BLAH_0 = StringData.forValue("blah");
FloatData PI = FloatData.forValue(3.14);
SoyValue BLAH_2 = StringData.forValue("blah");
SoyList list = ListImpl.forProviderList(EMPTY);
assertThat(list.length()).isEqualTo(0);
assertThat(list.asJavaList()).isEmpty();
assertThat(list.asResolvedJavaList()).isEmpty();
assertThat(list.get(0)).isNull();
assertThat(list.getProvider(0)).isNull();
list = ListImpl.forProviderList(ImmutableList.of(BLAH_0, PI, 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 ListImplTest method testSoyValueMethods.
@Test
public void testSoyValueMethods() {
SoyValue val1 = ListImpl.forProviderList(EMPTY);
// ListImpl is always truthy.
assertThat(val1.coerceToBoolean()).isTrue();
assertThat(val1.coerceToString()).isEqualTo("[]");
SoyValue val2 = ListImpl.forProviderList(EMPTY);
// ListImpl uses object identity.
assertThat(val1.equals(val2)).isFalse();
SoyValue val3 = ListImpl.forProviderList(ImmutableList.of(IntegerData.forValue(111), BooleanData.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 FloorFunctionTest method testComputeForJava.
@Test
public void testComputeForJava() {
FloorFunction floorFunction = new FloorFunction();
SoyValue float0 = FloatData.forValue(7.5);
assertThat(floorFunction.computeForJava(ImmutableList.of(float0))).isEqualTo(IntegerData.forValue(7));
SoyValue integer = IntegerData.forValue(14);
assertThat(floorFunction.computeForJava(ImmutableList.of(integer))).isEqualTo(IntegerData.forValue(14));
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrIndexOfFunctionTest method testComputeForJava_doesNotContainSanitizedContent.
@Test
public void testComputeForJava_doesNotContainSanitizedContent() {
StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
SoyValue arg0 = ordainAsSafe("foobarfoo", ContentKind.TEXT);
SoyValue arg1 = ordainAsSafe("baz", ContentKind.TEXT);
assertThat(strIndexOf.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(IntegerData.forValue(-1));
}
Aggregations