Search in sources :

Example 11 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class StrContainsFunctionTest method testComputeForJsSrc_lowPrecedenceArg.

@Test
public void testComputeForJsSrc_lowPrecedenceArg() {
    StrContainsFunction strContains = new StrContainsFunction();
    JsExpr arg0 = new JsExpr("'foo' + 'bar'", Operator.PLUS.getPrecedence());
    JsExpr arg1 = new JsExpr("'ba' + 'r'", Operator.PLUS.getPrecedence());
    assertThat(strContains.computeForJsSrc(ImmutableList.of(arg0, arg1))).isEqualTo(new JsExpr("('' + ('foo' + 'bar')).indexOf('' + ('ba' + 'r')) != -1", Operator.NOT_EQUAL.getPrecedence()));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 12 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class BidiDirAttrFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    BidiDirAttrFunction codeSnippet = new BidiDirAttrFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
    JsExpr textExpr = new JsExpr("TEXT_JS_CODE", Integer.MAX_VALUE);
    assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.of(textExpr))).isEqualTo(new JsExpr("soy.$$bidiDirAttr(1, TEXT_JS_CODE)", Integer.MAX_VALUE));
    assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr))).isEqualTo(new JsExpr("soy.$$bidiDirAttr(IS_RTL?-1:1, TEXT_JS_CODE)", Integer.MAX_VALUE));
    JsExpr isHtmlExpr = new JsExpr("IS_HTML_JS_CODE", Integer.MAX_VALUE);
    assertThat(BIDI_DIR_ATTR_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr))).isEqualTo(new JsExpr("soy.$$bidiDirAttr(-1, TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
    assertThat(codeSnippet.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr))).isEqualTo(new JsExpr("soy.$$bidiDirAttr(IS_RTL?-1:1, TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 13 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class BidiTextDirFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    BidiTextDirFunction bidiTextDirFunction = new BidiTextDirFunction();
    JsExpr textExpr = new JsExpr("TEXT_JS_CODE", Integer.MAX_VALUE);
    assertThat(bidiTextDirFunction.computeForJsSrc(ImmutableList.of(textExpr))).isEqualTo(new JsExpr("soy.$$bidiTextDir(TEXT_JS_CODE)", Integer.MAX_VALUE));
    JsExpr isHtmlExpr = new JsExpr("IS_HTML_JS_CODE", Integer.MAX_VALUE);
    assertThat(bidiTextDirFunction.computeForJsSrc(ImmutableList.of(textExpr, isHtmlExpr))).isEqualTo(new JsExpr("soy.$$bidiTextDir(TEXT_JS_CODE, IS_HTML_JS_CODE)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 14 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class EscapeHtmlDirectiveTest method testApplyForJsSrc.

@Test
public void testApplyForJsSrc() {
    EscapeHtmlDirective escapeHtmlDirective = new EscapeHtmlDirective();
    JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
    assertThat(escapeHtmlDirective.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$escapeHtml(opt_data.myKey)");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 15 with JsExpr

use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.

the class NoAutoescapeDirectiveTest method testApplyForJsSrc.

@Test
public void testApplyForJsSrc() {
    NoAutoescapeDirective noAutoescapeDirective = new NoAutoescapeDirective();
    JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
    assertThat(noAutoescapeDirective.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$filterNoAutoescape(opt_data.myKey)");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Aggregations

JsExpr (com.google.template.soy.jssrc.restricted.JsExpr)64 Test (org.junit.Test)42 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)3 ImmutableList (com.google.common.collect.ImmutableList)2 RequiresCollector (com.google.template.soy.jssrc.dsl.CodeChunk.RequiresCollector)2 SoyLibraryAssistedJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyLibraryAssistedJsSrcPrintDirective)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)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 SanitizedContent (com.google.template.soy.data.SanitizedContent)1 ContentKind (com.google.template.soy.data.SanitizedContent.ContentKind)1 SoyValue (com.google.template.soy.data.SoyValue)1 UnsafeSanitizedContentOrdainer (com.google.template.soy.data.UnsafeSanitizedContentOrdainer)1 SoyString (com.google.template.soy.data.restricted.SoyString)1 StringData (com.google.template.soy.data.restricted.StringData)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 WithValue (com.google.template.soy.jssrc.dsl.CodeChunk.WithValue)1 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)1