use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class TofuExceptionsTest method testExceptions_transclusion_failedFuture.
@Test
public void testExceptions_transclusion_failedFuture() {
Exception futureFailureCause = new Exception("boom");
SoyDict data = SoyValueConverterUtility.newDict("foo", immediateFailedFuture(futureFailureCause));
try {
tofu.newRenderer("ns.transclusionCaller").setData(data).render();
fail();
} catch (SoyTofuException ste) {
SoyFutureException sfe = (SoyFutureException) ste.getCause();
assertThat(sfe).hasMessageThat().isEqualTo("Error dereferencing future");
assertThat(sfe).hasCauseThat().isEqualTo(futureFailureCause);
assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$content\": When evaluating \"$foo\": Error dereferencing future");
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.transclusionCaller(no-path:17)");
assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.transclusionCallee(no-path:23)");
assertThat(ste.getStackTrace()[2].toString()).isEqualTo("ns.transclusionCaller(no-path:16)");
}
}
use of com.google.template.soy.data.SoyDict in project closure-templates by google.
the class TofuExceptionsTest method testExceptions_undefined.
@Test
public void testExceptions_undefined() throws Exception {
SoyDict data = SoyValueConverterUtility.newDict("foo.boo", 42);
// This is an exception that occurs during expression evaluation
try {
tofu.newRenderer("ns.callerTemplate").setData(data).render();
fail();
} catch (SoyTofuException ste) {
assertThat(ste).hasCauseThat().isNull();
assertThat(ste).hasMessageThat().isEqualTo("In 'print' tag, expression \"$foo.bad\" evaluates to undefined.");
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:11)");
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 TofuExceptionsTest method testExceptions_transclusion_wrongTypeFuture.
@Test
public void testExceptions_transclusion_wrongTypeFuture() {
SoyDict data = SoyValueConverterUtility.newDict("foo", Futures.immediateFuture("not an int"));
try {
tofu.newRenderer("ns.transclusionCaller").setData(data).render();
fail();
} catch (SoyTofuException ste) {
assertThat(ste).hasCauseThat().isNull();
assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$content\": When evaluating \"$foo\": Parameter type mismatch: " + "attempt to bind value 'not an int' (a StringData) to parameter 'foo' which " + "has a declared type of 'int'.");
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.transclusionCaller(no-path:14)");
assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.transclusionCaller(no-path:17)");
assertThat(ste.getStackTrace()[2].toString()).isEqualTo("ns.transclusionCallee(no-path:23)");
assertThat(ste.getStackTrace()[3].toString()).isEqualTo("ns.transclusionCaller(no-path:16)");
}
}
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);
}
Aggregations