Skip to content

Commit

Permalink
Avoid translating doubles to ints for residual asts (#424)
Browse files Browse the repository at this point in the history
Avoid int stringification for doubles with residual ASTs
  • Loading branch information
buildbreaker authored Jul 14, 2023
1 parent 378873c commit 73b20ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ public static String formatLiteral(Constant c) {
sb.append("\"");
return sb.toString();
case DOUBLE_VALUE:
String s = Double.toString(c.getDoubleValue());
if (s.endsWith(".0")) {
return s.substring(0, s.length() - 2);
}
return s;
return Double.toString(c.getDoubleValue());
case INT64_VALUE:
return Long.toString(c.getInt64Value());
case STRING_VALUE:
sb = new StringBuilder();
sb.append('\"');
s = c.getStringValue();
String s = c.getStringValue();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
switch (ch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ static TestCase[] checkTestCases() {
new TestCase()
.i("1.0 + 2.0 * 3.0 - 1.0 / 2.20202 != 66.6")
.r(
"_!=_(_-_(_+_(1~double, _*_(2~double, 3~double)~double^multiply_double)\n"
"_!=_(_-_(_+_(1.0~double, _*_(2.0~double, 3.0~double)~double^multiply_double)\n"
+ " ~double^add_double,\n"
+ " _/_(1~double, 2.20202~double)~double^divide_double)\n"
+ " _/_(1.0~double, 2.20202~double)~double^divide_double)\n"
+ " ~double^subtract_double,\n"
+ " 66.6~double)\n"
+ " ~bool^not_equals")
Expand Down Expand Up @@ -479,7 +479,7 @@ static TestCase[] checkTestCases() {
+ " )~bool^equals,\n"
+ " _==_(\n"
+ " z~dyn^z,\n"
+ " 1~double\n"
+ " 1.0~double\n"
+ " )~bool^equals\n"
+ " )~bool^logical_and\n"
+ ")~bool^logical_and")
Expand Down Expand Up @@ -797,13 +797,13 @@ static TestCase[] checkTestCases() {
+ " )~bool^logical_and,\n"
+ " _!=_(\n"
+ " x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_double_wrapper~wrapper(double),\n"
+ " 2~double\n"
+ " 2.0~double\n"
+ " )~bool^not_equals\n"
+ " )~bool^logical_and,\n"
+ " _&&_(\n"
+ " _==_(\n"
+ " x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_float_wrapper~wrapper(double),\n"
+ " 1~double\n"
+ " 1.0~double\n"
+ " )~bool^equals,\n"
+ " _!=_(\n"
+ " x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int32_wrapper~wrapper(int),\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public static String[][] testCases() {
"x * 2.0",
"_*_(\n"
+ " x^#1:*expr.Expr_IDENT_EXPR#,\n"
+ " 2^#3:*expr.Constant_DOUBLE_VALUE#\n"
+ " 2.0^#3:*expr.Constant_DOUBLE_VALUE#\n"
+ ")^#2:*expr.Expr_CALL_EXPR#",
"",
"",
Expand Down

0 comments on commit 73b20ce

Please sign in to comment.