Search in sources :

Example 41 with SoyValue

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"));
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 42 with SoyValue

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);
}
Also used : SoyLegacyObjectMap(com.google.template.soy.data.SoyLegacyObjectMap) SoyDict(com.google.template.soy.data.SoyDict) SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 43 with SoyValue

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);
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 44 with SoyValue

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);
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 45 with SoyValue

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);
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Aggregations

SoyValue (com.google.template.soy.data.SoyValue)61 Test (org.junit.Test)31 StringData (com.google.template.soy.data.restricted.StringData)5 ExprNode (com.google.template.soy.exprtree.ExprNode)4 SoyLegacyObjectMap (com.google.template.soy.data.SoyLegacyObjectMap)3 SoyList (com.google.template.soy.data.SoyList)3 ParentExprNode (com.google.template.soy.exprtree.ExprNode.ParentExprNode)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)2 SanitizedContent (com.google.template.soy.data.SanitizedContent)2 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)2 SoyDataException (com.google.template.soy.data.SoyDataException)2 SoyDict (com.google.template.soy.data.SoyDict)2 SoyRecord (com.google.template.soy.data.SoyRecord)2 FloatData (com.google.template.soy.data.restricted.FloatData)2 IntegerData (com.google.template.soy.data.restricted.IntegerData)2 SoyString (com.google.template.soy.data.restricted.SoyString)2 UndefinedData (com.google.template.soy.data.restricted.UndefinedData)2 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)2 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)2