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