Search in sources :

Example 56 with PyExpr

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

the class BidiDirAttrFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiDirAttrFunction codeSnippet = new BidiDirAttrFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    PyExpr textExpr = new PyStringExpr("'data'", Integer.MAX_VALUE);
    assertThat(codeSnippet.computeForPySrc(ImmutableList.of(textExpr)).getText()).isEqualTo("bidi.dir_attr(-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.dir_attr(-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 57 with PyExpr

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

the class BidiGlobalDirFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiGlobalDirFunction codeSnippet = new BidiGlobalDirFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    assertThat(codeSnippet.computeForPySrc(ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("-1 if IS_RTL else 1", PyExprUtils.pyPrecedenceForOperator(Operator.CONDITIONAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 58 with PyExpr

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

the class BidiMarkFunctionTest method testComputeForPySrc.

@Test
public void testComputeForPySrc() {
    BidiMarkFunction codeSnippet = new BidiMarkFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_PY_ISRTL_CODE_SNIPPET_PROVIDER);
    assertThat(codeSnippet.computeForPySrc(ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("'\\u200F' if (-1 if IS_RTL else 1) < 0 else '\\u200E'", PyExprUtils.pyPrecedenceForOperator(Operator.CONDITIONAL)));
}
Also used : PyExpr(com.google.template.soy.pysrc.restricted.PyExpr) Test(org.junit.Test)

Example 59 with PyExpr

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

the class BasicEscapeDirectiveTest method testPySrc.

@Test
public final void testPySrc() {
    PyExpr data = new PyStringExpr("'data'");
    // TODO(dcphillips): Add support for executing the sanitization call in Jython to verify it's
    // actual output. Currently the sanitization relies on integration tests for full verification.
    BasicEscapeDirective escapeJsString = new BasicEscapeDirective.EscapeJsString();
    assertThat(escapeJsString.applyForPySrc(data, ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("sanitize.escape_js_string('data')", Integer.MAX_VALUE));
    BasicEscapeDirective escapeHtmlAttribute = new BasicEscapeDirective.EscapeHtmlAttribute();
    assertThat(escapeHtmlAttribute.applyForPySrc(data, ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("sanitize.escape_html_attribute('data')", Integer.MAX_VALUE));
    BasicEscapeDirective filterCssValue = new BasicEscapeDirective.FilterCssValue();
    assertThat(filterCssValue.applyForPySrc(data, ImmutableList.<PyExpr>of())).isEqualTo(new PyExpr("sanitize.filter_css_value('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 60 with PyExpr

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

the class CleanHtmlDirectiveTest method testApplyForPySrc.

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