Search in sources :

Example 41 with JsExpr

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

the class StrSubFunctionTest method testComputeForJsSrc_endIndex.

@Test
public void testComputeForJsSrc_endIndex() {
    StrSubFunction strSub = new StrSubFunction();
    JsExpr arg0 = new JsExpr("'foo' + 'bar'", Operator.PLUS.getPrecedence());
    JsExpr arg1 = new JsExpr("3", Integer.MAX_VALUE);
    JsExpr arg2 = new JsExpr("5", Integer.MAX_VALUE);
    assertThat(strSub.computeForJsSrc(ImmutableList.of(arg0, arg1, arg2))).isEqualTo(new JsExpr("('' + ('foo' + 'bar')).substring(3,5)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 42 with JsExpr

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

the class BidiUnicodeWrapDirectiveTest method testApplyForJsSrc.

@Test
public void testApplyForJsSrc() {
    JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
    assertThat(BIDI_UNICODE_WRAP_DIRECTIVE_FOR_STATIC_LTR.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiUnicodeWrap(1, opt_data.myKey)");
    assertThat(BIDI_UNICODE_WRAP_DIRECTIVE_FOR_STATIC_RTL.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiUnicodeWrap(-1, opt_data.myKey)");
    BidiUnicodeWrapDirective codeSnippet = new BidiUnicodeWrapDirective(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
    assertThat(codeSnippet.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiUnicodeWrap(IS_RTL?-1:1, opt_data.myKey)");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 43 with JsExpr

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

the class TextDirectiveTest method testApplyForJsSrc.

@Test
public void testApplyForJsSrc() {
    TextDirective textDirective = new TextDirective();
    JsExpr jsExpr = new JsExpr("whatever", Integer.MAX_VALUE);
    assertThat(textDirective.applyForJsSrc(jsExpr, ImmutableList.<JsExpr>of()).getText()).isEqualTo("'' + whatever");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 44 with JsExpr

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

the class RandomIntFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    RandomIntFunction randomIntFunction = new RandomIntFunction();
    JsExpr argExpr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertThat(randomIntFunction.computeForJsSrc(ImmutableList.of(argExpr))).isEqualTo(new JsExpr("Math.floor(Math.random() * JS_CODE)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 45 with JsExpr

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

the class StrLenFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    StrLenFunction strLen = new StrLenFunction();
    JsExpr arg0 = new JsExpr("'foo' + 'bar'", Operator.PLUS.getPrecedence());
    assertThat(strLen.computeForJsSrc(ImmutableList.of(arg0))).isEqualTo(new JsExpr("('' + ('foo' + 'bar')).length", Integer.MAX_VALUE));
}
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