use of com.google.template.soy.shared.SoyGeneralOptions in project closure-templates by google.
the class RenderVisitorTest method testRenderDelegateVariantCall.
@Test
public void testRenderDelegateVariantCall() throws Exception {
String soyFileContent1 = "" + "{namespace ns1}\n" + "\n" + "/** @param greekB */\n" + "{template .callerTemplate}\n" + " {delcall myApp.myDelegate variant=\"'alpha'\"}\n" + // variant is string
" {param boo: 'zzz' /}\n" + " {/delcall}\n" + " {delcall myApp.myDelegate variant=\"$greekB\"}\n" + // variant is expression
" {param boo: 'zzz' /}\n" + " {/delcall}\n" + " {delcall myApp.myDelegate variant=\"'gamma'\"}\n" + // variant "gamma" not implemented
" {param boo: 'zzz' /}\n" + " {/delcall}\n" + " {delcall myApp.myDelegate variant=\"test.GLOBAL\"}\n" + // variant is a global expression
" {param boo: 'zzz' /}\n" + " {/delcall}\n" + "{/template}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate}\n" + // variant "" default
" 000empty\n" + "{/deltemplate}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"'alpha'\"}\n" + // variant "alpha" default
" 000alpha\n" + "{/deltemplate}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"'beta'\"}\n" + // variant "beta" default
" 000beta\n" + "{/deltemplate}\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"test.GLOBAL\"}\n" + // variant using global
" 000global\n" + "{/deltemplate}\n";
String soyFileContent2 = "" + "{delpackage SecretFeature}\n" + "{namespace ns2}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate}\n" + // variant "" in SecretFeature
" 111empty\n" + "{/deltemplate}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"'alpha'\"}\n" + // "alpha" in SecretFeature
" 111alpha\n" + "{/deltemplate}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"'beta'\"}\n" + // "beta" in SecretFeature
" 111beta\n" + "{/deltemplate}\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"test.GLOBAL\"}\n" + // variant using global
" 111global\n" + "{/deltemplate}\n";
String soyFileContent3 = "" + "{delpackage AlternateSecretFeature}\n" + "{namespace ns3}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate}\n" + // variant "" in AlternateSecretFeature
" 222empty\n" + "{/deltemplate}\n" + "\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"'alpha'\"}\n" + // variant "alpha" in Alternate
" 222alpha\n" + "{/deltemplate}\n" + "/** @param boo */\n" + "{deltemplate myApp.myDelegate variant=\"test.GLOBAL\"}\n" + // variant using global
" 222global\n" + // Note: No variant "beta" in AlternateSecretFeature.
"{/deltemplate}\n";
SoyGeneralOptions options = new SoyGeneralOptions();
options.setCompileTimeGlobals(ImmutableMap.<String, Object>of("test.GLOBAL", 1));
ParseResult result = SoyFileSetParserBuilder.forFileContents(soyFileContent1, soyFileContent2, soyFileContent3).options(options).errorReporter(FAIL).parse();
Predicate<String> activeDelPackageNames = Predicates.alwaysFalse();
assertThat(renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, activeDelPackageNames)).isEqualTo("000alpha000beta000empty000global");
activeDelPackageNames = Predicates.equalTo("SecretFeature");
assertThat(renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, activeDelPackageNames)).isEqualTo("111alpha111beta111empty111global");
activeDelPackageNames = Predicates.equalTo("AlternateSecretFeature");
assertThat(renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, activeDelPackageNames)).isEqualTo("222alpha000beta222empty222global");
activeDelPackageNames = Predicates.equalTo("NonexistentFeature");
assertThat(renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, activeDelPackageNames)).isEqualTo("000alpha000beta000empty000global");
activeDelPackageNames = Predicates.in(ImmutableSet.of("NonexistentFeature", "AlternateSecretFeature"));
assertThat(renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, activeDelPackageNames)).isEqualTo("222alpha000beta222empty222global");
try {
renderTemplateInFile(result, "ns1.callerTemplate", TEST_DATA, TEST_IJ_DATA, Predicates.in(ImmutableSet.of("SecretFeature", "AlternateSecretFeature")));
fail("expected RenderException");
} catch (RenderException e) {
assertThat(e).hasMessageThat().contains("For delegate template 'myApp.myDelegate:alpha', found two active implementations " + "with equal priority");
}
}
Aggregations