use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class IsNullFunctionTest method testComputeForPySrc.
@Test
public void testComputeForPySrc() {
PyExpr expr = new PyExpr("PY_CODE", Integer.MAX_VALUE);
assertThat(IS_NULL.computeForPySrc(ImmutableList.of(expr))).isEqualTo(new PyExpr("PY_CODE is None", PyExprUtils.pyPrecedenceForOperator(Operator.EQUAL)));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class LegacyObjectMapToMapFunctionTest method computeForPySrc.
@Test
public void computeForPySrc() {
PyExpr legacyObjectMap = new PyExpr("legacy_object_map", Integer.MAX_VALUE);
PyExpr map = LEGACY_OBJECT_MAP_TO_MAP.computeForPySrc(ImmutableList.of(legacyObjectMap));
// TODO(b/69064788): fix
assertThat(map).isEqualTo(legacyObjectMap);
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class MapToLegacyObjectMapFunctionTest method computeForPySrc.
@Test
public void computeForPySrc() {
PyExpr map = new PyExpr("map", Integer.MAX_VALUE);
PyExpr legacyObjectMap = MAP_TO_LEGACY_OBJECT_MAP.computeForPySrc(ImmutableList.of(map));
assertThat(legacyObjectMap.getText()).isEqualTo("runtime.map_to_legacy_object_map(map)");
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class RoundFunctionTest method testComputeForPySrc.
@Test
public void testComputeForPySrc() {
RoundFunction roundFunction = new RoundFunction();
String modifiedNumber = "(math.frexp(number)[0] + sys.float_info.epsilon)*2**math.frexp(number)[1]";
PyExpr floatExpr = new PyExpr("number", Integer.MAX_VALUE);
assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 0), 0)", Integer.MAX_VALUE));
PyExpr numDigitsAfterPtExpr = new PyExpr("0", Integer.MAX_VALUE);
assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 0), 0)", Integer.MAX_VALUE));
numDigitsAfterPtExpr = new PyExpr("4", Integer.MAX_VALUE);
assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", 4), 4)", Integer.MAX_VALUE));
numDigitsAfterPtExpr = new PyExpr("-2", Operator.NEGATIVE.getPrecedence());
assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", -2), -2)", Integer.MAX_VALUE));
numDigitsAfterPtExpr = new PyExpr("digits", Integer.MAX_VALUE);
assertThat(roundFunction.computeForPySrc(ImmutableList.of(floatExpr, numDigitsAfterPtExpr))).isEqualTo(new PyExpr("runtime.simplify_num(round(" + modifiedNumber + ", digits), digits)", Integer.MAX_VALUE));
}
use of com.google.template.soy.pysrc.restricted.PyExpr in project closure-templates by google.
the class StrSubFunctionTest method testComputeForPySrc_nonStringInput.
@Test
public void testComputeForPySrc_nonStringInput() {
StrSubFunction strSub = new StrSubFunction();
PyExpr base = new PyExpr("foobar", Integer.MAX_VALUE);
PyExpr start = new PyExpr("3", Integer.MAX_VALUE);
assertThat(strSub.computeForPySrc(ImmutableList.of(base, start))).isEqualTo(new PyStringExpr("(str(foobar))[3:]", Integer.MAX_VALUE));
}
Aggregations