use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class RewriteGenderMsgsVisitorTest method testRewriteWithPlural.
@Test
public void testRewriteWithPlural() {
String soyCode = "" + "{@param num : ?}\n" + "{@param userGender : ?}\n" + "{msg genders=\"$userGender\" desc=\"...\"}\n" + " {plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + "{/msg}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
assertEquals(// Note: Still has genders="..." in command text.
"{msg desc=\"...\" genders=\"$userGender\"}" + "{select $userGender}" + "{case 'female'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{case 'male'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{default}{plural $num}{case 1}Send it{default}Send {$num}{/plural}" + "{/select}", msgAfterRewrite.toSourceString());
// ------ Test that it has same msg id as equivalent msg using 'select'. ------
String soyCodeUsingSelect = "" + "{@param num : ?}\n" + "{@param userGender : ?}\n" + "{msg desc=\"...\"}\n" + " {select $userGender}\n" + " {case 'female'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {case 'male'}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {default}{plural $num}{case 1}Send it{default}Send {$num}{/plural}\n" + " {/select}\n" + "{/msg}\n";
SoyFileSetNode soyTreeUsingSelect = SoyFileSetParserBuilder.forTemplateContents(soyCodeUsingSelect).parse().fileSet();
MsgNode msgUsingSelect = (MsgNode) SharedTestUtils.getNode(soyTreeUsingSelect, 0, 0);
assertThat(MsgUtils.computeMsgIdForDualFormat(msgAfterRewrite)).isEqualTo(MsgUtils.computeMsgIdForDualFormat(msgUsingSelect));
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class RewriteGenderMsgsVisitorTest method testRewriteWithThreeGendersAndNoncollidingSelectVarNames.
@Test
public void testRewriteWithThreeGendersAndNoncollidingSelectVarNames() {
String soyCode = "" + "{@param target : ?}\n" + "{msg genders=\"$ij.userGender, $target[0].gender, $target[1].gender\" " + "desc=\"...\"}\n" + " You starred {$target[0].name}'s photo in {$target[1].name}'s album.\n" + "{/msg}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
String expectedInnerSelectSrc = "" + "{select $target[1].gender phname=\"TARGET_1_GENDER\"}" + "{case 'female'}You starred {$target[0].name}'s photo in {$target[1].name}'s album." + "{case 'male'}You starred {$target[0].name}'s photo in {$target[1].name}'s album." + "{default}You starred {$target[0].name}'s photo in {$target[1].name}'s album." + "{/select}";
String expectedMsgSrc = "" + // Note: Still has genders="..." in command text.
"{msg desc=\"...\" genders=\"$ij.userGender, $target[0].gender, $target[1].gender\"}" + "{select $ij.userGender}" + // note: 'phname' not specified because generated is same
"{case 'female'}" + "{select $target[0].gender phname=\"TARGET_0_GENDER\"}" + "{case 'female'}" + expectedInnerSelectSrc + "{case 'male'}" + expectedInnerSelectSrc + "{default}" + expectedInnerSelectSrc + "{/select}" + "{case 'male'}" + "{select $target[0].gender phname=\"TARGET_0_GENDER\"}" + "{case 'female'}" + expectedInnerSelectSrc + "{case 'male'}" + expectedInnerSelectSrc + "{default}" + expectedInnerSelectSrc + "{/select}" + "{default}" + "{select $target[0].gender phname=\"TARGET_0_GENDER\"}" + "{case 'female'}" + expectedInnerSelectSrc + "{case 'male'}" + expectedInnerSelectSrc + "{default}" + expectedInnerSelectSrc + "{/select}" + "{/select}";
assertThat(msgAfterRewrite.toSourceString()).isEqualTo(expectedMsgSrc);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class RewriteGenderMsgsVisitorTest method testRewriteSimple.
@Test
public void testRewriteSimple() {
String soyCode = "" + "{@param userGender : ?}\n" + "{msg genders=\"$userGender\" desc=\"Button text.\"}\n" + " Save\n" + "{/msg}\n";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
assertEquals(// Note: Still has genders="..." in command text.
"{msg desc=\"Button text.\" genders=\"$userGender\"}" + "{select $userGender}{case 'female'}Save{case 'male'}Save{default}Save{/select}", msgAfterRewrite.toSourceString());
// ------ Test that it has same msg id as equivalent msg using 'select'. ------
String soyCodeUsingSelect = "" + "{@param userGender : ?}\n" + "{msg desc=\"Button text.\"}\n" + " {select $userGender}\n" + " {case 'female'}Save\n" + " {case 'male'}Save\n" + " {default}Save\n" + " {/select}\n" + "{/msg}\n";
SoyFileSetNode soyTreeUsingSelect = SoyFileSetParserBuilder.forTemplateContents(soyCodeUsingSelect).parse().fileSet();
MsgNode msgUsingSelect = (MsgNode) SharedTestUtils.getNode(soyTreeUsingSelect, 0, 0);
assertThat(MsgUtils.computeMsgIdForDualFormat(msgAfterRewrite)).isEqualTo(MsgUtils.computeMsgIdForDualFormat(msgUsingSelect));
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class RewriteGenderMsgsVisitorTest method testRewriteWithGenderAndSelect.
@Test
public void testRewriteWithGenderAndSelect() {
String soyCode = "" + "{@param userGender : ?}\n" + "{@param targetGender : ?}\n" + "{msg genders=\"$userGender\" desc=\"Button text.\"}\n" + " {select $targetGender}\n" + " {case 'female'}Reply to her\n" + " {case 'male'}Reply to him\n" + " {default}Reply to them\n" + " {/select}\n" + "{/msg}\n";
String expandedSoyCode = "{msg desc=\"Button text.\" genders=\"$userGender\"}{select $userGender}" + "{case 'female'}{select $targetGender}{case 'female'}Reply to her" + "{case 'male'}Reply to him{default}Reply to them{/select}" + "{case 'male'}{select $targetGender}{case 'female'}Reply to her" + "{case 'male'}Reply to him{default}Reply to them{/select}" + "{default}{select $targetGender}{case 'female'}Reply to her" + "{case 'male'}Reply to him{default}Reply to them{/select}{/select}";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
assertThat(msgAfterRewrite.toSourceString()).isEqualTo(expandedSoyCode);
}
use of com.google.template.soy.soytree.SoyFileSetNode in project closure-templates by google.
the class RewriteGenderMsgsVisitorTest method testRewriteWithGenderSelectPlural.
@Test
public void testRewriteWithGenderSelectPlural() {
String soyCode = "" + "{@param n : ?}\n" + "{@param userGender : ?}\n" + "{@param targetGender : ?}\n" + "{msg genders=\"$userGender\" desc=\"...\"}\n" + " {select $targetGender}\n" + " {case 'female'}\n" + " {plural $n}{case 1}Send it to her{default}Send {$n} to her{/plural}\n" + " {default}\n" + " {plural $n}{case 1}Send it to them{default}Send {$n} to them{/plural}\n" + " {/select}\n" + "{/msg}\n";
// Note: Still has genders="..." in command text.
String expandedSoyCode = "{msg desc=\"...\" genders=\"$userGender\"}{select $userGender}{case 'female'}" + "{select $targetGender}{case 'female'}{plural $n}{case 1}Send it to her{default}" + "Send {$n} to her{/plural}{default}{plural $n}{case 1}Send it to them{default}" + "Send {$n} to them{/plural}{/select}{case 'male'}" + "{select $targetGender}{case 'female'}{plural $n}{case 1}Send it to her{default}" + "Send {$n} to her{/plural}{default}{plural $n}{case 1}Send it to them{default}" + "Send {$n} to them{/plural}{/select}{default}" + "{select $targetGender}{case 'female'}{plural $n}{case 1}Send it to her{default}" + "Send {$n} to her{/plural}{default}{plural $n}{case 1}Send it to them{default}" + "Send {$n} to them{/plural}{/select}{/select}";
ErrorReporter boom = ErrorReporter.exploding();
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forTemplateContents(soyCode).errorReporter(boom).parse().fileSet();
// After.
MsgNode msgAfterRewrite = (MsgNode) SharedTestUtils.getNode(soyTree, 0, 0);
assertThat(msgAfterRewrite.toSourceString()).isEqualTo(expandedSoyCode);
// ------ Test that it has same msg id as equivalent msg using 'select'. ------
String soyCodeUsingSelect = "" + "{@param n : ?}\n" + "{@param userGender : ?}\n" + "{@param targetGender : ?}\n" + "{msg desc=\"...\"}\n" + " {select $userGender}\n" + " {case 'female'}\n" + " {select $targetGender}\n" + " {case 'female'}\n" + " {plural $n}{case 1}Send it to her{default}Send {$n} to her{/plural}\n" + " {default}\n" + " {plural $n}{case 1}Send it to them{default}Send {$n} to them{/plural}\n" + " {/select}\n" + " {case 'male'}\n" + " {select $targetGender}\n" + " {case 'female'}\n" + " {plural $n}{case 1}Send it to her{default}Send {$n} to her{/plural}\n" + " {default}\n" + " {plural $n}{case 1}Send it to them{default}Send {$n} to them{/plural}\n" + " {/select}\n" + " {default}\n" + " {select $targetGender}\n" + " {case 'female'}\n" + " {plural $n}{case 1}Send it to her{default}Send {$n} to her{/plural}\n" + " {default}\n" + " {plural $n}{case 1}Send it to them{default}Send {$n} to them{/plural}\n" + " {/select}\n" + " {/select}\n" + "{/msg}\n";
SoyFileSetNode soyTreeUsingSelect = SoyFileSetParserBuilder.forTemplateContents(soyCodeUsingSelect).parse().fileSet();
MsgNode msgUsingSelect = (MsgNode) SharedTestUtils.getNode(soyTreeUsingSelect, 0, 0);
assertThat(MsgUtils.computeMsgIdForDualFormat(msgAfterRewrite)).isEqualTo(MsgUtils.computeMsgIdForDualFormat(msgUsingSelect));
}
Aggregations