use of com.google.template.soy.shared.restricted.SoyFunction in project closure-templates by google.
the class EvalVisitorTest method eval.
/**
* Evaluates the given expression and returns the result.
*
* @param expression The expression to evaluate.
* @return The expression result.
* @throws Exception If there's an error.
*/
private SoyValue eval(String expression) throws Exception {
PrintNode code = (PrintNode) SoyFileSetParserBuilder.forTemplateContents(// wrap in a function so we don't run into the 'can't print bools' error message
untypedTemplateBodyForExpression("fakeFunction(" + expression + ")")).addSoyFunction(new SoyFunction() {
@Override
public String getName() {
return "fakeFunction";
}
@Override
public Set<Integer> getValidArgsSizes() {
return ImmutableSet.of(1);
}
}).parse().fileSet().getChild(0).getChild(0).getChild(0);
ExprNode expr = ((FunctionNode) code.getExpr().getChild(0)).getChild(0);
EvalVisitor evalVisitor = new EvalVisitorFactoryImpl().create(TestingEnvironment.createForTest(testData, LOCALS), TEST_IJ_DATA, cssRenamingMap, xidRenamingMap, null, /* debugSoyTemplateInfo= */
false);
return evalVisitor.exec(expr);
}
use of com.google.template.soy.shared.restricted.SoyFunction in project closure-templates by google.
the class SharedModuleTest method testFunctionsSupportAllBackends.
@Test
public void testFunctionsSupportAllBackends() {
for (SoyFunction function : injector.getInstance(new Key<Set<SoyFunction>>() {
})) {
if (!FUNCTIONS_WITH_SPECIAL_TYPE_HANDLING.contains(function.getName())) {
assertThat(function).isInstanceOf(TypedSoyFunction.class);
}
assertThat(function).isInstanceOf(SoyJsSrcFunction.class);
assertThat(function).isInstanceOf(SoyJavaFunction.class);
assertThat(function).isInstanceOf(SoyJbcSrcFunction.class);
assertThat(function).isInstanceOf(SoyPySrcFunction.class);
}
}
Aggregations