use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class GenPyExprsVisitorTest method testMsgWithPlural.
@Test
public void testMsgWithPlural() {
String soyCode = "{@param numDrafts:?}\n" + "{msg desc=\"simple plural\"}" + "{plural $numDrafts}" + "{case 0}No drafts" + "{case 1}1 draft" + "{default}{$numDrafts} drafts" + "{/plural}" + "{/msg}";
String expectedPyCode = "translator_impl.render_plural(" + "translator_impl.prepare_plural(" + "###, " + "{" + "'=0': 'No drafts', " + "'=1': '1 draft', " + "'other': '{NUM_DRAFTS_2} drafts'" + "}, " + "('NUM_DRAFTS_1', 'NUM_DRAFTS_2')), " + "data.get('numDrafts'), " + "{" + "'NUM_DRAFTS_1': data.get('numDrafts'), " + "'NUM_DRAFTS_2': str(data.get('numDrafts'))" + "})";
assertThatSoyExpr(soyCode).compilesTo(new PyExpr(expectedPyCode, Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class GenPyExprsVisitorTest method testMsgWithSelect.
@Test
public void testMsgWithSelect() {
String soyCode = "{@param userGender:?}\n" + "{@param targetGender:?}\n" + "{msg desc=\"...\"}\n" + " {select $userGender}\n" + " {case 'female'}\n" + " {select $targetGender}\n" + " {case 'female'}Reply to her.\n" + " {case 'male'}Reply to him.\n" + " {default}Reply to them.\n" + " {/select}\n" + " {case 'male'}\n" + " {select $targetGender}\n" + " {case 'female'}Reply to her.\n" + " {case 'male'}Reply to him.\n" + " {default}Reply to them.\n" + " {/select}\n" + " {default}\n" + " {select $targetGender}\n" + " {case 'female'}Reply to her.\n" + " {case 'male'}Reply to him.\n" + " {default}Reply to them.\n" + " {/select}\n" + " {/select}\n" + "{/msg}\n";
String expectedPyCode = "translator_impl.render_icu(" + "translator_impl.prepare_icu(" + "###, " + "'{USER_GENDER,select," + "female{" + "{TARGET_GENDER,select," + "female{Reply to her.}" + "male{Reply to him.}" + "other{Reply to them.}}" + "}" + "male{" + "{TARGET_GENDER,select," + "female{Reply to her.}" + "male{Reply to him.}" + "other{Reply to them.}}" + "}" + "other{" + "{TARGET_GENDER,select," + "female{Reply to her.}" + "male{Reply to him.}" + "other{Reply to them.}}" + "}" + "}', " + "('USER_GENDER', 'TARGET_GENDER')), " + "{" + "'USER_GENDER': data.get('userGender'), " + "'TARGET_GENDER': data.get('targetGender')" + "})";
assertThatSoyExpr(soyCode).compilesTo(new PyExpr(expectedPyCode, Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class GenPyExprsVisitorTest method testIf.
@Test
public void testIf() {
String soyNodeCode = "{@param boo:?}\n" + "{@param goo:?}\n" + "{if $boo}\n" + " Blah\n" + "{elseif not $goo}\n" + " Bleh\n" + "{else}\n" + " Bluh\n" + "{/if}\n";
String expectedPyExprText = "'Blah' if data.get('boo') else 'Bleh' if not data.get('goo') else 'Bluh'";
assertThatSoyExpr(soyNodeCode).compilesTo(new PyExpr(expectedPyExprText, PyExprUtils.pyPrecedenceForOperator(Operator.CONDITIONAL)));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class GenPyExprsVisitorTest method testMsgOnlyLiteral.
@Test
public void testMsgOnlyLiteral() {
String soyCode = "{msg meaning=\"verb\" desc=\"The word 'Archive' used as a verb.\"}" + "Archive" + "{/msg}\n";
String expectedPyCode = "translator_impl.render_literal(" + "translator_impl.prepare_literal(" + "###, " + "'Archive'))";
assertThatSoyExpr(soyCode).compilesTo(new PyExpr(expectedPyCode, Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class GenPyExprsVisitorTest method testMsgWithHtmlNode.
@Test
public void testMsgWithHtmlNode() {
// msg with HTML tags and raw texts
String soyCode = "{@param url:?}\n" + "{msg desc=\"with link\"}" + "Please click <a href='{$url}'>here</a>." + "{/msg}";
String expectedPyCode = "translator_impl.render(" + "translator_impl.prepare(" + "###, " + "'Please click {START_LINK}here{END_LINK}.', " + "('START_LINK', 'END_LINK')), " + "{" + "'START_LINK': ''.join(['<a href=\\'',str(data.get('url')),'\\'>']), " + "'END_LINK': '</a>'" + "})";
assertThatSoyExpr(soyCode).compilesTo(new PyExpr(expectedPyCode, Integer.MAX_VALUE));
}
Aggregations