use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrSubFunctionTest method testComputeForJava_endIndex.
@Test
public void testComputeForJava_endIndex() {
StrSubFunction strSub = new StrSubFunction();
SoyValue arg0 = StringData.forValue("foobarfoo");
SoyValue arg1 = IntegerData.forValue(2);
SoyValue arg2 = IntegerData.forValue(7);
assertThat(strSub.computeForJava(ImmutableList.of(arg0, arg1, arg2))).isEqualTo(StringData.forValue("obarf"));
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class AugmentMapFunctionTest method testComputeForJava.
@Test
public void testComputeForJava() {
AugmentMapFunction augmentMapFunction = new AugmentMapFunction();
SoyLegacyObjectMap origMap = SoyValueConverterUtility.newDict("aaa", "blah", "bbb", "bleh", "ccc", SoyValueConverterUtility.newDict("xxx", 2));
SoyLegacyObjectMap additionalMap = SoyValueConverterUtility.newDict("aaa", "bluh", "ccc", SoyValueConverterUtility.newDict("yyy", 5));
SoyDict augmentedDict = (SoyDict) augmentMapFunction.computeForJava(ImmutableList.<SoyValue>of(origMap, additionalMap));
assertThat(augmentedDict.getField("aaa").stringValue()).isEqualTo("bluh");
assertThat(augmentedDict.getItem(StringData.forValue("bbb")).stringValue()).isEqualTo("bleh");
assertThat(((SoyDict) augmentedDict.getField("ccc")).getField("yyy").integerValue()).isEqualTo(5);
assertThat(((SoyDict) augmentedDict.getField("ccc")).getField("xxx")).isEqualTo(null);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class RandomIntFunctionTest method testComputeForJava.
@Test
public void testComputeForJava() {
RandomIntFunction randomIntFunction = new RandomIntFunction();
SoyValue arg = IntegerData.ONE;
assertThat(randomIntFunction.computeForJava(ImmutableList.of(arg))).isEqualTo(IntegerData.ZERO);
arg = IntegerData.forValue(3);
Set<Integer> seenResults = Sets.newHashSetWithExpectedSize(3);
for (int i = 0; i < 100; i++) {
int result = randomIntFunction.computeForJava(ImmutableList.of(arg)).integerValue();
assertThat(result).isAtLeast(0);
assertThat(result).isAtMost(2);
seenResults.add(result);
if (seenResults.size() == 3) {
break;
}
}
assertThat(seenResults).hasSize(3);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrContainsFunctionTest method testComputeForJava_doesNotContainSanitizedContent.
@Test
public void testComputeForJava_doesNotContainSanitizedContent() {
StrContainsFunction strContains = new StrContainsFunction();
SoyValue arg0 = ordainAsSafe("foobarfoo", ContentKind.TEXT);
SoyValue arg1 = ordainAsSafe("baz", ContentKind.TEXT);
assertThat(strContains.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(BooleanData.FALSE);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrContainsFunctionTest method testComputeForJava_doesNotContainString.
@Test
public void testComputeForJava_doesNotContainString() {
StrContainsFunction strContains = new StrContainsFunction();
SoyValue arg0 = StringData.forValue("foobarfoo");
SoyValue arg1 = StringData.forValue("baz");
assertThat(strContains.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(BooleanData.FALSE);
}
Aggregations