Search in sources :

Example 6 with PyStringExpr

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

the class StrSubFunctionTest method testComputeForPySrc_endIndex.

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

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

the class StrSubFunctionTest method testComputeForPySrc_noEndIndex.

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

Example 8 with PyStringExpr

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

the class BidiUnicodeWrapDirectiveTest method testApplyForPySrc.

@Test
public void testApplyForPySrc() {
    BidiUnicodeWrapDirective codeSnippet = new BidiUnicodeWrapDirective(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.unicode_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 9 with PyStringExpr

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

the class TruncateDirectiveTest method testApplyForPySrc.

@Test
public void testApplyForPySrc() {
    TruncateDirective truncateDirective = new TruncateDirective();
    PyExpr data = new PyStringExpr("'data'", Integer.MAX_VALUE);
    PyExpr dataRef = new PyExpr("opt_data[myKey]", Integer.MAX_VALUE);
    PyExpr maxLenExpr = new PyExpr("8", Integer.MAX_VALUE);
    PyExpr trueExpr = new PyExpr("True", Integer.MAX_VALUE);
    PyExpr falseExpr = new PyExpr("False", Integer.MAX_VALUE);
    assertThat(truncateDirective.applyForPySrc(data, ImmutableList.of(maxLenExpr)).getText()).isEqualTo("directives.truncate('data', 8, True)");
    assertThat(truncateDirective.applyForPySrc(data, ImmutableList.of(maxLenExpr, trueExpr)).getText()).isEqualTo("directives.truncate('data', 8, True)");
    assertThat(truncateDirective.applyForPySrc(data, ImmutableList.of(maxLenExpr, falseExpr)).getText()).isEqualTo("directives.truncate('data', 8, False)");
    assertThat(truncateDirective.applyForPySrc(dataRef, ImmutableList.of(maxLenExpr)).getText()).isEqualTo("directives.truncate(str(opt_data[myKey]), 8, True)");
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) PyStringExpr(com.google.template.soy.pysrc.restricted.PyStringExpr) Test(org.junit.Test)

Example 10 with PyStringExpr

use of com.google.template.soy.pysrc.restricted.PyStringExpr 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)

Aggregations

PyStringExpr (com.google.template.soy.pysrc.restricted.PyStringExpr)22 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)21 Test (org.junit.Test)14 LinkedHashMap (java.util.LinkedHashMap)3 MsgPluralNode (com.google.template.soy.soytree.MsgPluralNode)2 SoyNode (com.google.template.soy.soytree.SoyNode)2 ParentSoyNode (com.google.template.soy.soytree.SoyNode.ParentSoyNode)2 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 SoyMsgPluralCaseSpec (com.google.template.soy.msgs.restricted.SoyMsgPluralCaseSpec)1 SoyMsgPluralPart (com.google.template.soy.msgs.restricted.SoyMsgPluralPart)1 PyFunctionExprBuilder (com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder)1 PyListExpr (com.google.template.soy.pysrc.restricted.PyListExpr)1 SoyPySrcPrintDirective (com.google.template.soy.pysrc.restricted.SoyPySrcPrintDirective)1 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)1 AbstractParentSoyNode (com.google.template.soy.soytree.AbstractParentSoyNode)1 CallNode (com.google.template.soy.soytree.CallNode)1 CallParamContentNode (com.google.template.soy.soytree.CallParamContentNode)1 CallParamNode (com.google.template.soy.soytree.CallParamNode)1 CallParamValueNode (com.google.template.soy.soytree.CallParamValueNode)1 IfCondNode (com.google.template.soy.soytree.IfCondNode)1