Search in sources :

Example 61 with PyExpr

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

the class IsNonnullFunctionTest method testComputeForPySrc.

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

Example 62 with PyExpr

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

the class KeysFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    KeysFunction keysFunction = new KeysFunction();
    PyExpr dict = new PyExpr("dictionary", Integer.MAX_VALUE);
    assertThat(keysFunction.computeForPySrc(ImmutableList.of(dict))).isEqualTo(new PyListExpr("(dictionary).keys()", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyListExpr(com.google.template.soy.pysrc.restricted.PyListExpr) Test(org.junit.Test)

Example 63 with PyExpr

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

the class LengthFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    LengthFunction lengthFunction = new LengthFunction();
    PyExpr expr = new PyExpr("data", Integer.MAX_VALUE);
    assertThat(lengthFunction.computeForPySrc(ImmutableList.of(expr))).isEqualTo(new PyExpr("len(data)", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 64 with PyExpr

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

the class MaxFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    MaxFunction maxFunction = new MaxFunction();
    PyExpr expr0 = new PyExpr("number0", Integer.MAX_VALUE);
    PyExpr expr1 = new PyExpr("number1", Integer.MAX_VALUE);
    assertThat(maxFunction.computeForPySrc(ImmutableList.of(expr0, expr1))).isEqualTo(new PyExpr("max(number0, number1)", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 65 with PyExpr

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

the class BidiEndEdgeFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiEndEdgeFunction codeSnippet = new BidiEndEdgeFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    assertThat(codeSnippet.computeForPySrc(ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("'left' if (-1 if IS_RTL else 1) < 0 else 'right'", PyExprUtils.pyPrecedenceForOperator(Operator.CONDITIONAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) 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