Skip to content

Commit

Permalink
incremental parsing example and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 11, 2024
1 parent b8bea86 commit a1cdf9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions test/corelib/src/json_parser_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ TEST_CASE("test_incremental_parsing")
{
SECTION("Array of strings")
{
std::vector<std::string> chunks = {"[fal", "se, ", "t", "rue", ", null", ",", "1", "234", ",\"Hello ", "World\"", "]"};
std::vector<std::string> chunks = {"[fal", "se, ", "t", "rue", ", null", ",", "1", "234", ",\"Hello ", "World\",",
"0.", "1234", "]"};
std::size_t index = 0;

auto read_chunk = [&](jsoncons::parser_input& input, std::error_code& /*ec*/) -> bool
Expand Down Expand Up @@ -265,12 +266,13 @@ TEST_CASE("test_incremental_parsing")

json j = decoder.get_result();
REQUIRE(j.is_array());
REQUIRE(j.size() == 5);
REQUIRE(j.size() == 6);
CHECK_FALSE(j[0].as<bool>());
CHECK(j[1].as<bool>());
CHECK(j[2].is_null());
CHECK(j[3].as<int>() == 1234);
CHECK(j[4].as<std::string>() == "Hello World");
CHECK(j[5].as<double>() == 0.1234);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/corelib/src/json_reader_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_CASE("test json_reader buffered read")
CHECK(j.as<std::string>() == str);
}

/*SECTION("number with split buffer")
SECTION("number with split buffer")
{
std::string str(stream_source<char>::default_max_buffer_size-7, 'a');
std::string neg_num("-123456789.123456789");
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST_CASE("test json_reader buffered read")
REQUIRE(j.is_array());
REQUIRE(j.size() == 2);
CHECK(j[1].is_null());
}*/
}
}

void test_json_reader_error(const std::string& text, const std::error_code& ec)
Expand Down

0 comments on commit a1cdf9b

Please sign in to comment.