Skip to content

Commit

Permalink
[ggj][codegen][test] fix: handle floating-point types for test codege…
Browse files Browse the repository at this point in the history
…n assertEquals (#544)

* fix: align resname ctors with superclass variants

* fix: avoid type collisions - refactor {Concrete,Vapor}Ref into AstNodes

* fix: better message null checks in Parser

* fix: map proto.Empty RPC types to void in ServiceClient

* fix: improve import(shortName) state-keeping in ImportWriterVisitor

* fix: fix stub pkg for all ServiceSettingsStub usages

* fix: handle older protos with javaMultipleFiles=false

* fix: gate isPaged on all fields for monolith back-compat

* fix: fail early if bazel lacks a grpc_service_config.json file

* fix: add Bazel handling for lack of resname helper classes

* fix: reverse conditional

* fix: handle floating-point types for test codegen assertEquals
  • Loading branch information
miraleung authored Nov 21, 2020
1 parent ab0c02f commit 33c2dea
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,23 @@ private static MethodDefinition createRpcTestMethod(
.build();
Expr expectedFieldExpr = checkExprFn.apply(requestVarExpr);
Expr actualFieldExpr = checkExprFn.apply(actualRequestVarExpr);
List<Expr> assertEqualsArguments = new ArrayList<>();
assertEqualsArguments.add(expectedFieldExpr);
assertEqualsArguments.add(actualFieldExpr);
if (TypeNode.isFloatingPointType(field.type())) {
boolean isFloat = field.type().equals(TypeNode.FLOAT);
assertEqualsArguments.add(
ValueExpr.withValue(
PrimitiveValue.builder()
.setType(isFloat ? TypeNode.FLOAT : TypeNode.DOUBLE)
.setValue(String.format("0.0001%s", isFloat ? "f" : ""))
.build()));
}
methodExprs.add(
MethodInvocationExpr.builder()
.setStaticReferenceType(STATIC_TYPES.get("Assert"))
.setMethodName("assertEquals")
.setArguments(expectedFieldExpr, actualFieldExpr)
.setArguments(assertEqualsArguments)
.build());
}
} else {
Expand Down

0 comments on commit 33c2dea

Please sign in to comment.