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));
}
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)");
}
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");
}
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));
}
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));
}
Aggregations