Skip to content

Commit 80dba56

Browse files
committed
Add tests for issues with string-to-double conversions (Tencent#849, Tencent#1249, Tencent#1251, Tencent#1253, Tencent#1256, Tencent#1259)
1 parent 01c7174 commit 80dba56

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/unittest/readertest.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ static void TestParseDouble() {
377377
d = d.Value() * 0.5;
378378
}
379379
}
380+
381+
// Issue 1249
382+
TEST_DOUBLE(fullPrecision, "0e100", 0.0);
383+
384+
// Issue 1251
385+
TEST_DOUBLE(fullPrecision, "128.74836467836484838364836483643636483648e-336", 0.0);
386+
387+
// Issue 1256
388+
TEST_DOUBLE(fullPrecision,
389+
"6223372036854775296.1701512723685473547372536854755293372036854685477"
390+
"529752233737201701512337200972013723685473123372036872036854236854737"
391+
"247372368372367752975258547752975254729752547372368737201701512354737"
392+
"83723677529752585477247372368372368547354737253685475529752",
393+
6223372036854775808.0);
394+
380395
#undef TEST_DOUBLE
381396
}
382397

@@ -443,7 +458,7 @@ TEST(Reader, ParseNumber_Error) {
443458
for (int i = 1; i < 310; i++)
444459
n1e309[i] = '0';
445460
n1e309[310] = '\0';
446-
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, n1e309, 0, 309);
461+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, n1e309, 0, 310);
447462
}
448463
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e309", 0, 5);
449464

@@ -455,6 +470,25 @@ TEST(Reader, ParseNumber_Error) {
455470
TEST_NUMBER_ERROR(kParseErrorNumberMissExponent, "1e", 2, 2);
456471
TEST_NUMBER_ERROR(kParseErrorNumberMissExponent, "1e_", 2, 2);
457472

473+
// Issue 849
474+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1.8e308", 0, 7);
475+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "5e308", 0, 5);
476+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e309", 0, 5);
477+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1.0e310", 0, 7);
478+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1.00e310", 0, 8);
479+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "-1.8e308", 0, 8);
480+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "-1e309", 0, 6);
481+
482+
// Issue 1253
483+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "2e308", 0, 5);
484+
485+
// Issue 1259
486+
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
487+
"88474320368547737236837236775298547354737253685475547552933720368546854775297525"
488+
"29337203685468547770151233720097201372368547312337203687203685423685123372036872"
489+
"03685473724737236837236775297525854775297525472975254737236873720170151235473783"
490+
"7236737247372368772473723683723456789012E66", 0, 283);
491+
458492
#undef TEST_NUMBER_ERROR
459493
}
460494

0 commit comments

Comments
 (0)