Search in sources :

Example 1 with PyExpr

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

the class IsNullFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    PyExpr expr = new PyExpr("PY_CODE", Integer.MAX_VALUE);
    assertThat(IS_NULL.computeForPySrc(ImmutableList.of(expr))).isEqualTo(new PyExpr("PY_CODE is None", PyExprUtils.pyPrecedenceForOperator(Operator.EQUAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 2 with PyExpr

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

the class LegacyObjectMapToMapFunctionTest method computeForPySrc.

@Test
public void computeForPySrc() {
    PyExpr legacyObjectMap = new PyExpr("legacy_object_map", Integer.MAX_VALUE);
    PyExpr map = LEGACY_OBJECT_MAP_TO_MAP.computeForPySrc(ImmutableList.of(legacyObjectMap));
    // TODO(b/69064788): fix
    assertThat(map).isEqualTo(legacyObjectMap);
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 3 with PyExpr

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

the class MapToLegacyObjectMapFunctionTest method computeForPySrc.

@Test
public void computeForPySrc() {
    PyExpr map = new PyExpr("map", Integer.MAX_VALUE);
    PyExpr legacyObjectMap = MAP_TO_LEGACY_OBJECT_MAP.computeForPySrc(ImmutableList.of(map));
    assertThat(legacyObjectMap.getText()).isEqualTo("runtime.map_to_legacy_object_map(map)");
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 4 with PyExpr

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

the class RoundFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    RoundFunction roundFunction = new RoundFunction();
    String modifiedNumber = "(math.frexp(number)[0] + sys.float_info.epsilon)*2**math.frexp(number)[1]";
    PyExpr floatExpr = new PyExpr("number", Integer.MAX_VALUE);
    assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 0), 0)", Integer.MAX_VALUE));
    PyExpr numDigitsAfterPtExpr = new PyExpr("0", Integer.MAX_VALUE);
    assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 0), 0)", Integer.MAX_VALUE));
    numDigitsAfterPtExpr = new PyExpr("4", Integer.MAX_VALUE);
    assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 4), 4)", Integer.MAX_VALUE));
    numDigitsAfterPtExpr = new PyExpr("-2", Operator.NEGATIVE.getPrecedence());
    assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", -2), -2)", Integer.MAX_VALUE));
    numDigitsAfterPtExpr = new PyExpr("digits", Integer.MAX_VALUE);
    assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", digits), digits)", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 5 with PyExpr

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

the class StrSubFunctionTest method testComputeForPySrc_nonStringInput.

@Test
public void testComputeForPySrc_nonStringInput() {
    StrSubFunction strSub = new StrSubFunction();
    PyExpr base = new PyExpr("foobar", Integer.MAX_VALUE);
    PyExpr start = new PyExpr("3", Integer.MAX_VALUE);
    assertThat(strSub.computeForPySrc(ImmutableList.of(base, start))).isEqualTo(new PyStringExpr("(str(foobar))[3:]", Integer.MAX_VALUE));
}
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