Skip to content

Commit 2850895

Browse files
authored
add e notation tests (#975)
1 parent 931923f commit 2850895

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/test/java/com/fasterxml/jackson/core/read/NumberParsingTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,60 @@ public void testNegativeMaxNumberLength() {
881881
}
882882
}
883883

884+
public void testBigIntegerWithENotation() throws Exception {
885+
final String DOC = "1e5";
886+
887+
// TODO broken for MODE_DATA_INPUT
888+
final int[] modes = new int[]{
889+
MODE_INPUT_STREAM,
890+
MODE_INPUT_STREAM_THROTTLED,
891+
MODE_READER,
892+
MODE_READER_THROTTLED
893+
};
894+
for (int mode : modes) {
895+
try (JsonParser p = createParser(jsonFactory(), mode, DOC)) {
896+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
897+
assertEquals(100000L, p.getBigIntegerValue().longValue());
898+
}
899+
}
900+
}
901+
902+
public void testLongWithENotation() throws Exception {
903+
final String DOC = "1e5";
904+
905+
// TODO broken for MODE_DATA_INPUT
906+
final int[] modes = new int[]{
907+
MODE_INPUT_STREAM,
908+
MODE_INPUT_STREAM_THROTTLED,
909+
MODE_READER,
910+
MODE_READER_THROTTLED
911+
};
912+
for (int mode : modes) {
913+
try (JsonParser p = createParser(jsonFactory(), mode, DOC)) {
914+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
915+
assertEquals(100000L, p.getLongValue());
916+
}
917+
}
918+
}
919+
920+
public void testIntWithENotation() throws Exception {
921+
final String DOC = "1e5";
922+
923+
// TODO broken for MODE_DATA_INPUT
924+
final int[] modes = new int[]{
925+
MODE_INPUT_STREAM,
926+
MODE_INPUT_STREAM_THROTTLED,
927+
MODE_READER,
928+
MODE_READER_THROTTLED
929+
};
930+
for (int mode : modes) {
931+
try (JsonParser p = createParser(jsonFactory(), mode, DOC)) {
932+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
933+
assertEquals(100000, p.getIntValue());
934+
}
935+
}
936+
}
937+
884938
/*
885939
/**********************************************************
886940
/* Helper methods

0 commit comments

Comments
 (0)