Search in sources :

Example 11 with PyExpr

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

the class CeilingFunctionTest method testComputeForPySrc.

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

Example 12 with PyExpr

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

the class BidiMarkAfterFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiMarkAfterFunction codeSnippet = new BidiMarkAfterFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    PyExpr textExpr = new PyStringExpr("'data'");
    assertThat(codeSnippet.computeForPySrc(ImmutableList.of(textExpr)).getText()).isEqualTo("bidi.mark_after(-1 if IS_RTL else 1, 'data')");
    PyExpr isHtmlExpr = new PyExpr("is_html", Integer.MAX_VALUE);
    assertThat(codeSnippet.computeForPySrc(ImmutableList.of(textExpr, isHtmlExpr)).getText()).isEqualTo("bidi.mark_after(-1 if IS_RTL else 1, 'data', is_html)");
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyStringExpr(com.google.template.soy.pysrc.restricted.PyStringExpr) Test(org.junit.Test)

Example 13 with PyExpr

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

the class StrLenFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    StrLenFunction strLen = new StrLenFunction();
    PyExpr string = new PyStringExpr("'data'");
    assertThat(strLen.computeForPySrc(ImmutableList.of(string))).isEqualTo(new PyExpr("len('data')", Integer.MAX_VALUE));
    PyExpr data = new PyExpr("data", Integer.MAX_VALUE);
    assertThat(strLen.computeForPySrc(ImmutableList.of(data))).isEqualTo(new PyExpr("len(str(data))", 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 14 with PyExpr

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

the class BidiSpanWrapDirectiveTest method testApplyForPySrc.

@Test
public void testApplyForPySrc() {
    BidiSpanWrapDirective codeSnippet = new BidiSpanWrapDirective(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    PyExpr data = new PyStringExpr("'data'");
    assertThat(codeSnippet.applyForPySrc(data, ImmutableList.<PyExpr>of()).getText()).isEqualTo("bidi.span_wrap(-1 if IS_RTL else 1, 'data')");
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyStringExpr(com.google.template.soy.pysrc.restricted.PyStringExpr) Test(org.junit.Test)

Example 15 with PyExpr

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

the class BidiTextDirFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiTextDirFunction bidiTextDirFunction = new BidiTextDirFunction();
    PyExpr data = new PyStringExpr("'data'");
    assertThat(bidiTextDirFunction.computeForPySrc(ImmutableList.of(data)).getText()).isEqualTo("bidi.text_dir('data')");
    PyExpr isHtml = new PyExpr("is_html", Integer.MAX_VALUE);
    assertThat(bidiTextDirFunction.computeForPySrc(ImmutableList.of(data, isHtml)).getText()).isEqualTo("bidi.text_dir('data', is_html)");
}
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