Search in sources :

Example 51 with PyExpr

use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.

the class TextDirectiveTest method testApplyForPySrc.

@Test
public void testApplyForPySrc() {
    TextDirective textDirective = new TextDirective();
    PyExpr pyExpr = new PyExpr("whatever", Integer.MAX_VALUE);
    assertThat(textDirective.applyForPySrc(pyExpr, ImmutableList.<PyExpr>of()).getText()).isEqualTo("str(whatever)");
    PyExpr stringExpr = new PyStringExpr("'string'", Integer.MAX_VALUE);
    assertThat(textDirective.applyForPySrc(stringExpr, ImmutableList.<PyExpr>of()).getText()).isEqualTo("'string'");
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyStringExpr(com.google.template.soy.pysrc.restricted.PyStringExpr) Test(org.junit.Test)

Example 52 with PyExpr

use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.

the class AugmentMapFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    AugmentMapFunction augmentMapFunction = new AugmentMapFunction();
    PyExpr baseMapExpr = new PyExpr("base", Integer.MAX_VALUE);
    PyExpr additionalMapExpr = new PyExpr("additional", Integer.MAX_VALUE);
    assertThat(augmentMapFunction.computeForPySrc(ImmutableList.of(baseMapExpr, additionalMapExpr))).isEqualTo(new PyExpr("dict(base, **additional)", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 53 with PyExpr

use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.

the class RandomIntFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    RandomIntFunction randomIntFunction = new RandomIntFunction();
    PyExpr argExpr = new PyExpr("upper", Integer.MAX_VALUE);
    assertThat(randomIntFunction.computeForPySrc(ImmutableList.of(argExpr))).isEqualTo(new PyExpr("random.randint(0, upper - 1)", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 54 with PyExpr

use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.

the class StrContainsFunctionTest method testComputeForPySrc_nonStringInput.

@Test
public void testComputeForPySrc_nonStringInput() {
    StrContainsFunction strContains = new StrContainsFunction();
    PyExpr base = new PyExpr("foobar", Integer.MAX_VALUE);
    PyExpr substring = new PyExpr("bar", Integer.MAX_VALUE);
    assertThat(strContains.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("(str(foobar)).find(str(bar)) != -1", PyExprUtils.pyPrecedenceForOperator(Operator.NOT_EQUAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 55 with PyExpr

use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.

the class StrContainsFunctionTest method testComputeForPySrc_stringInput.

@Test
public void testComputeForPySrc_stringInput() {
    StrContainsFunction strContains = new StrContainsFunction();
    PyExpr base = new PyStringExpr("'foobar'", Integer.MAX_VALUE);
    PyExpr substring = new PyStringExpr("'bar'", Integer.MAX_VALUE);
    assertThat(strContains.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("('foobar').find('bar') != -1", PyExprUtils.pyPrecedenceForOperator(Operator.NOT_EQUAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyStringExpr(com.google.template.soy.pysrc.restricted.PyStringExpr) Test(org.junit.Test)

Aggregations

PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)82 Test (org.junit.Test)58 PyStringExpr (com.google.template.soy.pysrc.restricted.PyStringExpr)21 PyFunctionExprBuilder (com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder)6 LinkedHashMap (java.util.LinkedHashMap)4 SoyPySrcPrintDirective (com.google.template.soy.pysrc.restricted.SoyPySrcPrintDirective)3 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)3 SoyNode (com.google.template.soy.soytree.SoyNode)3 ExprNode (com.google.template.soy.exprtree.ExprNode)2 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)2 PyListExpr (com.google.template.soy.pysrc.restricted.PyListExpr)2 MsgPluralNode (com.google.template.soy.soytree.MsgPluralNode)2 PrintNode (com.google.template.soy.soytree.PrintNode)2 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)2 ParentSoyNode (com.google.template.soy.soytree.SoyNode.ParentSoyNode)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1