mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-15 17:51:06 +00:00
chore(json): Add more unit tests.
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
ad6e904a53
commit
985188c8ad
1 changed files with 23 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
|||
namespace dfly {
|
||||
using namespace std;
|
||||
using namespace jsoncons;
|
||||
using namespace jsoncons::literals;
|
||||
|
||||
class JsonTest : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -40,4 +41,26 @@ TEST_F(JsonTest, Basic) {
|
|||
EXPECT_EQ(1.1, j["reputons"][0]["rating"].as_double());
|
||||
}
|
||||
|
||||
TEST_F(JsonTest, Query) {
|
||||
json j = R"(
|
||||
{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}}
|
||||
)"_json;
|
||||
|
||||
json out = jsonpath::json_query(j, "$..*");
|
||||
EXPECT_EQ(R"([{},{"a":1},{"a":1,"b":2},1,1,2])"_json, out);
|
||||
|
||||
json j2 = R"(
|
||||
{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}
|
||||
)"_json;
|
||||
|
||||
// json_query always returns arrays.
|
||||
// See here: https://github.com/danielaparker/jsoncons/issues/82
|
||||
// Therefore we are going to only support the "extended" semantics
|
||||
// of json API (as they are called in AWS documentation).
|
||||
out = jsonpath::json_query(j2, "$.address");
|
||||
EXPECT_EQ(R"([{"street":"21 2nd Street","city":"New York",
|
||||
"state":"NY","zipcode":"10021-3100"}])"_json,
|
||||
out);
|
||||
}
|
||||
|
||||
} // namespace dfly
|
Loading…
Reference in a new issue