Skip to content

Commit b50b4cc

Browse files
yhageramidvidy
authored andcommitted
CXX-587: Added tests for empty documents and empty array conversion to string
Closes #286 Signed-off-by: Adam Midvidy <amidvidy@gmail.com>
1 parent 5fc10a9 commit b50b4cc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bsoncxx/test/json.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ TEST_CASE("valid json is converted to equivalent BSON") {
3030
REQUIRE(expected_view.length() == actual_view.length());
3131
REQUIRE(0 == memcmp(expected_view.data(), actual_view.data(), expected_view.length()));
3232
}
33+
34+
TEST_CASE("empty document is converted correctly to json string") {
35+
using namespace bsoncxx;
36+
37+
REQUIRE(0 == to_json(builder::stream::document{}.view()).compare("{\n\n}"));
38+
}
39+
40+
TEST_CASE("empty array is converted correctly to json string") {
41+
using bsoncxx::to_json;
42+
using namespace bsoncxx::builder::stream;
43+
auto doc = document{};
44+
doc << "array" << open_array << close_array;
45+
REQUIRE(0 == to_json(doc.view()["array"]).compare("\"array\" : [\n\n]"));
46+
}

0 commit comments

Comments
 (0)