use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class BidiSpanWrapDirectiveTest method testApplyForJsSrc.
@Test
public void testApplyForJsSrc() {
JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
assertThat(BIDI_SPAN_WRAP_DIRECTIVE_FOR_STATIC_LTR.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiSpanWrap(1, opt_data.myKey)");
assertThat(BIDI_SPAN_WRAP_DIRECTIVE_FOR_STATIC_RTL.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiSpanWrap(-1, opt_data.myKey)");
BidiSpanWrapDirective codeSnippet = new BidiSpanWrapDirective(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
assertThat(codeSnippet.applyForJsSrc(dataRef, ImmutableList.<JsExpr>of()).getText()).isEqualTo("soy.$$bidiSpanWrap(IS_RTL?-1:1, opt_data.myKey)");
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class BidiGlobalDirFunctionTest method testComputeForJsSrc.
@Test
public void testComputeForJsSrc() {
assertThat(BIDI_GLOBAL_DIR_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("1", Integer.MAX_VALUE));
assertThat(BIDI_GLOBAL_DIR_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("-1", Integer.MAX_VALUE));
BidiGlobalDirFunction codeSnippet = new BidiGlobalDirFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
assertThat(codeSnippet.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("IS_RTL?-1:1", Operator.CONDITIONAL.getPrecedence()));
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class BidiMarkFunctionTest method testComputeForJsSrc.
@Test
public void testComputeForJsSrc() {
assertThat(BIDI_MARK_FUNCTION_FOR_STATIC_LTR.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("'\\u200E'", Integer.MAX_VALUE));
assertThat(BIDI_MARK_FUNCTION_FOR_STATIC_RTL.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("'\\u200F'", Integer.MAX_VALUE));
BidiMarkFunction codeSnippet = new BidiMarkFunction(SharedRestrictedTestUtils.BIDI_GLOBAL_DIR_FOR_JS_ISRTL_CODE_SNIPPET_PROVIDER);
assertThat(codeSnippet.computeForJsSrc(ImmutableList.<JsExpr>of())).isEqualTo(new JsExpr("(IS_RTL?-1:1) < 0 ? '\\u200F' : '\\u200E'", Operator.CONDITIONAL.getPrecedence()));
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class CleanHtmlDirectiveTest method testApplyForJsSrc_optionalSafeTags.
@Test
public void testApplyForJsSrc_optionalSafeTags() {
CleanHtmlDirective cleanHtml = new CleanHtmlDirective();
JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
// All possible OptionalSafeTags.
ImmutableList<JsExpr> optionalSafeTagsAsJsExprs = Arrays.stream(OptionalSafeTag.values()).map(OptionalSafeTag.TO_TAG_NAME).map(input -> new JsExpr(String.format("'%s'", input), Integer.MAX_VALUE)).collect(toImmutableList());
assertThat(cleanHtml.applyForJsSrc(dataRef, optionalSafeTagsAsJsExprs).getText()).isEqualTo("soy.$$cleanHtml(opt_data.myKey, ['li', 'ol', 'span', 'ul'])");
// Only the specified optional safe tags are passed to $$cleanHtml.
assertThat(cleanHtml.applyForJsSrc(dataRef, ImmutableList.of(new JsExpr("'span'", Integer.MAX_VALUE))).getText()).isEqualTo("soy.$$cleanHtml(opt_data.myKey, ['span'])");
// Invalid optional safe tags.
try {
cleanHtml.applyForJsSrc(dataRef, ImmutableList.of(new JsExpr("'unsupported'", Integer.MAX_VALUE)));
fail();
} catch (IllegalArgumentException e) {
// Test passes.
}
try {
cleanHtml.applyForJsSrc(dataRef, ImmutableList.of(new JsExpr("'li, ul'", Integer.MAX_VALUE)));
fail();
} catch (IllegalArgumentException e) {
// Test passes.
}
// Invalid parameter syntax.
try {
cleanHtml.applyForJsSrc(dataRef, ImmutableList.of(new JsExpr("$myExtraSafeTags", Integer.MAX_VALUE)));
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessageThat().isEqualTo("The cleanHtml directive expects arguments to be tag name string " + "literals, such as 'span'. Encountered: $myExtraSafeTags");
}
}
use of com.google.template.soy.jssrc.restricted.JsExpr in project closure-templates by google.
the class InsertWordBreaksDirectiveTest method testApplyForJsSrc.
@Test
public void testApplyForJsSrc() {
InsertWordBreaksDirective insertWordBreaksDirective = new InsertWordBreaksDirective();
JsExpr dataRef = new JsExpr("opt_data.myKey", Integer.MAX_VALUE);
JsExpr arg = new JsExpr("8", Integer.MAX_VALUE);
assertThat(insertWordBreaksDirective.applyForJsSrc(dataRef, ImmutableList.of(arg)).getText()).isEqualTo("soy.$$insertWordBreaks(opt_data.myKey, 8)");
}
Aggregations