use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class TofuExceptionsTest method testExceptions_badType.
@Test
public void testExceptions_badType() throws Exception {
SoyDict data = SoyValueConverterUtility.newDict("foo", "not a record");
// This is an exception that occurs during template calling due to a type checkin
try {
tofu.newRenderer("ns.callerTemplate").setData(data).render();
fail();
} catch (SoyTofuException ste) {
assertThat(ste).hasCauseThat().isNull();
assertThat(ste).hasMessageThat().isEqualTo("Parameter type mismatch: attempt to bind value 'not a record' (a StringData) to " + "parameter 'foo' which has a declared type of '[bad: string, boo: int]'.");
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:8)");
assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.callerTemplate(no-path:5)");
}
}
use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class AugmentMapFunction method computeForJava.
// IntelliJ
@SuppressWarnings("ConstantConditions")
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
Preconditions.checkArgument(arg0 instanceof SoyLegacyObjectMap, "First argument to augmentMap() function is not SoyLegacyObjectMap.");
Preconditions.checkArgument(arg1 instanceof SoyLegacyObjectMap, "Second argument to augmentMap() function is not SoyLegacyObjectMap.");
// TODO: Support map with nonstring key.
Preconditions.checkArgument(arg0 instanceof SoyDict, "First argument to augmentMap() function is not SoyDict. Currently, augmentMap() doesn't" + " support maps that are not dicts (it is a todo).");
Preconditions.checkArgument(arg1 instanceof SoyDict, "Second argument to augmentMap() function is not SoyDict. Currently, augmentMap() doesn't" + " support maps that are not dicts (it is a todo).");
return BasicFunctionsRuntime.augmentMap((SoyDict) arg0, (SoyDict) arg1);
}
use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class RenderVisitorTest method testRenderNestedSelects.
@Test
public void testRenderNestedSelects() throws Exception {
String templateBody = "{@param gender1: ?}\n" + "{@param gender2: ?}\n" + "{@param person1: ?}\n" + "{@param person2: ?}\n" + " {msg desc=\"Nested selects\"}\n" + " {select $gender1}\n" + " {case 'female'}\n" + " {select $gender2}\n" + " {case 'female'}\n" + " {$person1} shared her photos with {$person2} and her friends.\n" + " {default}\n" + " {$person1} shared her photos with {$person2} and his friends.\n" + " {/select}\n" + " {default}\n" + " {select $gender2}\n" + " {case 'female'}" + " {$person1} shared his photos with {$person2} and her friends.\n" + " {default}" + " {$person1} shared his photos with {$person2} and his friends.\n" + " {/select}\n" + " {/select}\n" + " {/msg}\n";
SoyDict data = SoyValueConverterUtility.newDict("person1", "Alice", "gender1", "female", "person2", "Lara", "gender2", "female");
assertRenderWithData(templateBody, data, "Alice shared her photos with Lara and her friends.");
data = SoyValueConverterUtility.newDict("person1", "Alice", "gender1", "female", "person2", "Mark", "gender2", "male");
assertRenderWithData(templateBody, data, "Alice shared her photos with Mark and his friends.");
data = SoyValueConverterUtility.newDict("person1", "Bob", "gender1", "male", "person2", "Mark", "gender2", "male");
assertRenderWithData(templateBody, data, " Bob shared his photos with Mark and his friends.");
data = SoyValueConverterUtility.newDict("person1", "Bob", "gender1", "male", "person2", "Lara", "gender2", "female");
assertRenderWithData(templateBody, data, " Bob shared his photos with Lara and her friends.");
}
use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class RenderVisitorTest method testRenderPluralWithRuntimeErrors.
@Test
public void testRenderPluralWithRuntimeErrors() throws Exception {
String templateBody = "{@param n_people: ?}\n" + "{@param person: ?}\n" + " {msg desc=\"Simple plural message\"}\n" + " {plural $n_people offset=\"1\"}\n" + " {case 0}Nobody shared photos.\n" + " {case 1}Only {$person} shared photos.\n" + " {default}{$person} and {remainder($n_people)} others shared photos.\n" + " {/plural}\n" + " {/msg}\n";
SoyDict data = SoyValueConverterUtility.newDict("person", "Bob", "n_people", "nobody");
assertRenderExceptionWithData(templateBody, data, "Plural expression \"$n_people\" doesn't evaluate to number.");
}
use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class RenderVisitorTest method testRenderPluralWithEmbeddedHtmlElements.
@Test
public void testRenderPluralWithEmbeddedHtmlElements() throws Exception {
/**
* Link to open up the email options dialog.
*
* @param num {number} Number of people who will be notified via email.
*/
String templateBody = "{@param num: ?}\n" + "{msg desc=\"[ICU Syntax] Explanatory text saying that with current\n" + " settings, $num people will be notified via email\"}\n" + " {plural $num}\n" + " {case 0}\n" + " Notify people via email ›\n" + " {case 1}\n" + " Notify{sp}\n" + " <span class=\"{css('sharebox-id-email-number')}\">{$num}</span>{sp}\n" + " person via email ›\n" + " {default}\n" + " Notify{sp}\n" + " <span class=\"{css('sharebox-id-email-number')}\">{$num}</span>{sp}\n" + " people via email ›\n" + " {/plural}\n" + " {/msg}\n";
SoyDict data = SoyValueConverterUtility.newDict("num", 1);
assertRenderWithData(templateBody, data, "Notify <span class=\"sharebox-id-email-number\">1</span> person via email ›");
data = SoyValueConverterUtility.newDict("num", 10);
assertRenderWithData(templateBody, data, "Notify <span class=\"sharebox-id-email-number\">10</span> people via email ›");
}
Aggregations