BSON: Support objects with string members

This commit is contained in:
Julian Becker 2018-09-15 11:33:24 +02:00
parent 0c0f2e44b5
commit 6c447de076
4 changed files with 100 additions and 14 deletions

View file

@ -183,5 +183,31 @@ TEST_CASE("BSON")
CHECK(json::from_bson(result) == j);
CHECK(json::from_bson(result, true, false) == j);
}
SECTION("non-empty object with string")
{
json j =
{
{ "entry", "bsonstr" }
};
std::vector<uint8_t> expected =
{
0x18, 0x00, 0x00, 0x00, // size (little endian)
0x02, /// entry: string (UTF-8)
'e', 'n', 't', 'r', 'y', '\x00',
0x08, 0x00, 0x00, 0x00, 'b', 's', 'o', 'n', 's', 't', 'r', '\x00',
0x00 // end marker
};
const auto result = json::to_bson(j);
CHECK(result == expected);
// roundtrip
CHECK(json::from_bson(result) == j);
CHECK(json::from_bson(result, true, false) == j);
}
}
}