+ more test cases
This commit is contained in:
parent
ea94518a64
commit
d3216300b2
2 changed files with 30 additions and 5 deletions
|
@ -1940,11 +1940,6 @@ JSON::Parser::~Parser()
|
||||||
*/
|
*/
|
||||||
void JSON::Parser::parse(JSON& result)
|
void JSON::Parser::parse(JSON& result)
|
||||||
{
|
{
|
||||||
if (_buffer == nullptr)
|
|
||||||
{
|
|
||||||
error("unexpected end of file");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (_current)
|
switch (_current)
|
||||||
{
|
{
|
||||||
case ('{'):
|
case ('{'):
|
||||||
|
|
|
@ -1335,6 +1335,36 @@ TEST_CASE("Parser")
|
||||||
CHECK_THROWS_AS(JSON::parse("infinity"), std::invalid_argument);
|
CHECK_THROWS_AS(JSON::parse("infinity"), std::invalid_argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("number (float)")
|
||||||
|
{
|
||||||
|
// accept the exact values
|
||||||
|
CHECK(JSON::parse("0.5") == JSON(0.5));
|
||||||
|
CHECK(JSON::parse("-0.5") == JSON(-0.5));
|
||||||
|
CHECK(JSON::parse("1.5") == JSON(1.5));
|
||||||
|
CHECK(JSON::parse("-1.5") == JSON(-1.5));
|
||||||
|
CHECK(JSON::parse("12345678.5") == JSON(12345678.5));
|
||||||
|
CHECK(JSON::parse("-12345678.5") == JSON(-12345678.5));
|
||||||
|
|
||||||
|
CHECK(JSON::parse("17.5e0") == JSON(17.5));
|
||||||
|
CHECK(JSON::parse("17.5e1") == JSON(175));
|
||||||
|
CHECK(JSON::parse("17.5e3") == JSON(17500));
|
||||||
|
CHECK(JSON::parse("17.5e+0") == JSON(17.5));
|
||||||
|
CHECK(JSON::parse("17.5e+1") == JSON(175));
|
||||||
|
CHECK(JSON::parse("17.5e+3") == JSON(17500));
|
||||||
|
CHECK(JSON::parse("17.5E0") == JSON(17.5));
|
||||||
|
CHECK(JSON::parse("17.5E1") == JSON(175));
|
||||||
|
CHECK(JSON::parse("17.5E3") == JSON(17500));
|
||||||
|
CHECK(JSON::parse("17.5E+0") == JSON(17.5));
|
||||||
|
CHECK(JSON::parse("17.5E+1") == JSON(175));
|
||||||
|
CHECK(JSON::parse("17.5E+3") == JSON(17500));
|
||||||
|
CHECK(JSON::parse("10000.5e-0") == JSON(10000.5));
|
||||||
|
CHECK(JSON::parse("10000.5e-1") == JSON(1000.05));
|
||||||
|
CHECK(JSON::parse("10000.5e-4") == JSON(1.00005));
|
||||||
|
CHECK(JSON::parse("10000.5E-0") == JSON(10000.5));
|
||||||
|
CHECK(JSON::parse("10000.5E-1") == JSON(1000.05));
|
||||||
|
CHECK(JSON::parse("10000.5E-4") == JSON(1.00005));
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("parse from C++ string")
|
SECTION("parse from C++ string")
|
||||||
{
|
{
|
||||||
std::string s = "{ \"foo\": [1,2,true] }";
|
std::string s = "{ \"foo\": [1,2,true] }";
|
||||||
|
|
Loading…
Reference in a new issue