Search in sources :

Example 36 with SoyValue

use of com.google.template.soy.data.SoyValue in project closure-templates by google.

the class RoundFunctionTest method testComputeForJava.

@Test
public void testComputeForJava() {
    RoundFunction roundFunction = new RoundFunction();
    SoyValue float0 = FloatData.forValue(9753.141592653590);
    assertThat(roundFunction.computeForJava(ImmutableList.of(float0))).isEqualTo(IntegerData.forValue(9753));
    SoyValue numDigitsAfterPt = IntegerData.ZERO;
    assertThat(roundFunction.computeForJava(ImmutableList.of(float0, numDigitsAfterPt))).isEqualTo(IntegerData.forValue(9753));
    numDigitsAfterPt = IntegerData.forValue(4);
    assertThat(roundFunction.computeForJava(ImmutableList.of(float0, numDigitsAfterPt))).isEqualTo(FloatData.forValue(9753.1416));
    numDigitsAfterPt = IntegerData.forValue(-2);
    assertThat(roundFunction.computeForJava(ImmutableList.of(float0, numDigitsAfterPt))).isEqualTo(IntegerData.forValue(9800));
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 37 with SoyValue

use of com.google.template.soy.data.SoyValue in project closure-templates by google.

the class StrIndexOfFunctionTest method testComputeForJava_containsString.

@Test
public void testComputeForJava_containsString() {
    StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
    SoyValue arg0 = StringData.forValue("foobarfoo");
    SoyValue arg1 = StringData.forValue("bar");
    assertThat(strIndexOf.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(IntegerData.forValue(3));
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 38 with SoyValue

use of com.google.template.soy.data.SoyValue in project closure-templates by google.

the class StrIndexOfFunctionTest method testComputeForJava_doesNotContainString.

@Test
public void testComputeForJava_doesNotContainString() {
    StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
    SoyValue arg0 = StringData.forValue("foobarfoo");
    SoyValue arg1 = StringData.forValue("baz");
    assertThat(strIndexOf.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(IntegerData.forValue(-1));
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 39 with SoyValue

use of com.google.template.soy.data.SoyValue in project closure-templates by google.

the class StrSubFunctionTest method testComputeForJava_noEndIndex.

@Test
public void testComputeForJava_noEndIndex() {
    StrSubFunction strSub = new StrSubFunction();
    SoyValue arg0 = StringData.forValue("foobarfoo");
    SoyValue arg1 = IntegerData.forValue(2);
    assertThat(strSub.computeForJava(ImmutableList.of(arg0, arg1))).isEqualTo(StringData.forValue("obarfoo"));
}
Also used : SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 40 with SoyValue

use of com.google.template.soy.data.SoyValue in project closure-templates by google.

the class StrSubFunctionTest method testComputeForJava_endIndex_SanitizedContent.

@Test
public void testComputeForJava_endIndex_SanitizedContent() {
    StrSubFunction strSub = new StrSubFunction();
    SoyValue arg0 = ordainAsSafe("foobarfoo", ContentKind.TEXT);
    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)

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