Skip to content

Commit 78851a7

Browse files
Generate non-numeric floats in protocol tests (#355)
1 parent f89b4ec commit 78851a7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,21 @@ public Void stringNode(StringNode node) {
955955
// Handle blobs needing to be converted from strings to their input type of UInt8Array.
956956
if (workingShape.isBlobShape()) {
957957
writer.write("Uint8Array.from($S, c => c.charCodeAt(0)),", node.getValue());
958+
} else if (workingShape.isFloatShape() || workingShape.isDoubleShape()) {
959+
switch (node.getValue()) {
960+
case "NaN":
961+
writer.write("NaN,");
962+
break;
963+
case "Infinity":
964+
writer.write("Infinity,");
965+
break;
966+
case "-Infinity":
967+
writer.write("-Infinity,");
968+
break;
969+
default:
970+
throw new CodegenException(String.format(
971+
"Unexpected string value for `%s`: \"%s\"", workingShape.getId(), node.getValue()));
972+
}
958973
} else {
959974
writer.write("$S,", node.getValue());
960975
}

0 commit comments

Comments
 (0)