use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class TextDirectiveTest method testApplyForPySrc.
@Test
public void testApplyForPySrc() {
TextDirective textDirective = new TextDirective();
PyExpr pyExpr = new PyExpr("whatever", Integer.MAX_VALUE);
assertThat(textDirective.applyForPySrc(pyExpr, ImmutableList.<PyExpr>of()).getText()).isEqualTo("str(whatever)");
PyExpr stringExpr = new PyStringExpr("'string'", Integer.MAX_VALUE);
assertThat(textDirective.applyForPySrc(stringExpr, ImmutableList.<PyExpr>of()).getText()).isEqualTo("'string'");
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class AugmentMapFunctionTest method testComputeForPySrc.
@Test
public void testComputeForPySrc() {
AugmentMapFunction augmentMapFunction = new AugmentMapFunction();
PyExpr baseMapExpr = new PyExpr("base", Integer.MAX_VALUE);
PyExpr additionalMapExpr = new PyExpr("additional", Integer.MAX_VALUE);
assertThat(augmentMapFunction.computeForPySrc(ImmutableList.of(baseMapExpr, additionalMapExpr))).isEqualTo(new PyExpr("dict(base, **additional)", Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class RandomIntFunctionTest method testComputeForPySrc.
@Test
public void testComputeForPySrc() {
RandomIntFunction randomIntFunction = new RandomIntFunction();
PyExpr argExpr = new PyExpr("upper", Integer.MAX_VALUE);
assertThat(randomIntFunction.computeForPySrc(ImmutableList.of(argExpr))).isEqualTo(new PyExpr("random.randint(0, upper - 1)", Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class StrContainsFunctionTest method testComputeForPySrc_nonStringInput.
@Test
public void testComputeForPySrc_nonStringInput() {
StrContainsFunction strContains = new StrContainsFunction();
PyExpr base = new PyExpr("foobar", Integer.MAX_VALUE);
PyExpr substring = new PyExpr("bar", Integer.MAX_VALUE);
assertThat(strContains.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("(str(foobar)).find(str(bar)) != -1", PyExprUtils.pyPrecedenceForOperator(Operator.NOT_EQUAL)));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class StrContainsFunctionTest method testComputeForPySrc_stringInput.
@Test
public void testComputeForPySrc_stringInput() {
StrContainsFunction strContains = new StrContainsFunction();
PyExpr base = new PyStringExpr("'foobar'", Integer.MAX_VALUE);
PyExpr substring = new PyStringExpr("'bar'", Integer.MAX_VALUE);
assertThat(strContains.computeForPySrc(ImmutableList.of(base, substring))).isEqualTo(new PyExpr("('foobar').find('bar') != -1", PyExprUtils.pyPrecedenceForOperator(Operator.NOT_EQUAL)));
}
Aggregations