Search in sources :

Example 51 with JsExpr

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

the class TruncateDirectiveTest method testApplyForJsSrc.

@Test
public void testApplyForJsSrc() {
    TruncateDirective truncateDirective = new TruncateDirective();
    JsExpr dataRefJsExpr = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
    JsExpr maxLenJsExpr = new JsExpr("8", Integer.MAX_VALUE);
    JsExpr trueJsExpr = new JsExpr("true", Integer.MAX_VALUE);
    JsExpr falseJsExpr = new JsExpr("false", Integer.MAX_VALUE);
    assertThat(truncateDirective.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr)).getText()).isEqualTo("soy.$$truncate(opt_data.myKey, 8, true)");
    assertThat(truncateDirective.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr, trueJsExpr)).getText()).isEqualTo("soy.$$truncate(opt_data.myKey, 8, true)");
    assertThat(truncateDirective.applyForJsSrc(dataRefJsExpr, ImmutableList.of(maxLenJsExpr, falseJsExpr)).getText()).isEqualTo("soy.$$truncate(opt_data.myKey, 8, false)");
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 52 with JsExpr

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

the class CeilingFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    CeilingFunction ceilingFunction = new CeilingFunction();
    JsExpr expr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertThat(ceilingFunction.computeForJsSrc(ImmutableList.of(expr))).isEqualTo(new JsExpr("Math.ceil(JS_CODE)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 53 with JsExpr

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

the class IsNonnullFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    IsNonnullFunction isNonnullFunction = new IsNonnullFunction();
    JsExpr expr = new JsExpr("JS_CODE", Integer.MAX_VALUE);
    assertThat(isNonnullFunction.computeForJsSrc(ImmutableList.of(expr))).isEqualTo(new JsExpr("JS_CODE != null", Operator.NOT_EQUAL.getPrecedence()));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 54 with JsExpr

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

the class MaxFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    MaxFunction maxFunction = new MaxFunction();
    JsExpr expr0 = new JsExpr("JS_CODE_0", Integer.MAX_VALUE);
    JsExpr expr1 = new JsExpr("JS_CODE_1", Integer.MAX_VALUE);
    assertThat(maxFunction.computeForJsSrc(ImmutableList.of(expr0, expr1))).isEqualTo(new JsExpr("Math.max(JS_CODE_0, JS_CODE_1)", Integer.MAX_VALUE));
}
Also used : JsExpr(com.google.template.soy.jssrc.restricted.JsExpr) Test(org.junit.Test)

Example 55 with JsExpr

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

the class BidiEndEdgeFunctionTest method testComputeForJsSrc.

@Test
public void testComputeForJsSrc() {
    assertThat(BIDI_END_EDGE_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("'right'", Integer.MAX_VALUE));
    assertThat(BIDI_END_EDGE_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("'left'", Integer.MAX_VALUE));
    BidiEndEdgeFunction codeSnippet = new BidiEndEdgeFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
    assertThat(codeSnippet.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("(IS_RTL?-1:1) < 0 ? 'left' : 'right'", Operator.CONDITIONAL.getPrecedence()));
}
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