Search in sources :

Example 46 with PyExpr

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

the class FloorFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    FloorFunction floorFunction = new FloorFunction();
    PyExpr expr = new PyExpr("number", Integer.MAX_VALUE);
    assertThat(floorFunction.computeForPySrc(ImmutableList.of(expr))).isEqualTo(new PyExpr("int(math.floor(number))", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 47 with PyExpr

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

the class MinFunctionTest method testComputeForPySrc.

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

Example 48 with PyExpr

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

the class StrIndexOfFunctionTest method testComputeForPySrc_stringInput.

@Test
public void testComputeForPySrc_stringInput() {
    StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
    PyExpr base = new PyStringExpr("'foobar'", Integer.MAX_VALUE);
    PyExpr substring = new PyStringExpr("'bar'", Integer.MAX_VALUE);
    assertThat(strIndexOf.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("('foobar').find('bar')", 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)

Example 49 with PyExpr

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

the class StrIndexOfFunctionTest method testComputeForPySrc_nonStringInput.

@Test
public void testComputeForPySrc_nonStringInput() {
    StrIndexOfFunction strIndexOf = new StrIndexOfFunction();
    PyExpr base = new PyExpr("foobar", Integer.MAX_VALUE);
    PyExpr substring = new PyExpr("bar", Integer.MAX_VALUE);
    assertThat(strIndexOf.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("(str(foobar)).find(str(bar))", Integer.MAX_VALUE));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 50 with PyExpr

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

the class ChangeNewlineToBrDirectiveTest method testApplyForPySrc.

@Test
public void testApplyForPySrc() {
    ChangeNewlineToBrDirective directive = new ChangeNewlineToBrDirective();
    PyExpr data = new PyExpr("'data'", Integer.MAX_VALUE);
    assertThat(directive.applyForPySrc(data, ImmutableList.<PyExpr>of()).getText()).isEqualTo("sanitize.change_newline_to_br('data')");
}
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