1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

BSON: support doubles

This commit is contained in:
Julian Becker
2018-09-15 03:23:54 +02:00
parent 9a0dddc5d2
commit 0c0f2e44b5
4 changed files with 115 additions and 31 deletions

View File

@ -136,28 +136,52 @@ TEST_CASE("BSON")
CHECK(json::from_bson(result, true, false) == j);
}
// SECTION("non-empty object with double")
// {
// json j =
// {
// { "entry", true }
// };
SECTION("non-empty object with bool")
{
json j =
{
{ "entry", false }
};
// std::vector<uint8_t> expected =
// {
// 0x14, 0x00, 0x00, 0x00, // size (little endian)
// 0x01, /// entry: double
// 'e', 'n', 't', 'r', 'y', '\x00',
// 0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40,
// 0x00 // end marker
// };
std::vector<uint8_t> expected =
{
0x0D, 0x00, 0x00, 0x00, // size (little endian)
0x08, // entry: boolean
'e', 'n', 't', 'r', 'y', '\x00',
0x00, // value = false
0x00 // end marker
};
// const auto result = json::to_bson(j);
// CHECK(result == expected);
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);
// }
// roundtrip
CHECK(json::from_bson(result) == j);
CHECK(json::from_bson(result, true, false) == j);
}
SECTION("non-empty object with double")
{
json j =
{
{ "entry", 4.2 }
};
std::vector<uint8_t> expected =
{
0x14, 0x00, 0x00, 0x00, // size (little endian)
0x01, /// entry: double
'e', 'n', 't', 'r', 'y', '\x00',
0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40,
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);
}
}
}