@@ -79,48 +79,93 @@ TEST_CASE("jmespath_expression tests")
79
79
80
80
TEST_CASE (" jmespath issue" )
81
81
{
82
- std::string jtext = R"(
82
+ SECTION ( " issue 1 " )
83
83
{
84
- "locations": [
85
- {"name": "Seattle", "state": "WA"},
86
- {"name": "New York", "state": "NY"},
87
- {"name": "Bellevue", "state": "WA"},
88
- {"name": "Olympia", "state": "WA"}
89
- ]
90
- }
91
- )" ;
92
-
93
- std::string expr = R"(
94
- {
95
- name: locations[].name,
96
- state: locations[].state
84
+ std::string jtext = R"(
85
+ {
86
+ "locations": [
87
+ {"name": "Seattle", "state": "WA"},
88
+ {"name": "New York", "state": "NY"},
89
+ {"name": "Bellevue", "state": "WA"},
90
+ {"name": "Olympia", "state": "WA"}
91
+ ]
92
+ }
93
+ )" ;
94
+
95
+ std::string expr = R"(
96
+ {
97
+ name: locations[].name,
98
+ state: locations[].state
99
+ }
100
+ )" ;
101
+
102
+ auto doc = ojson::parse (jtext);
103
+
104
+ auto result = jmespath::search (doc, expr);
105
+
106
+ // std::cout << pretty_print(result) << "\n\n";
97
107
}
98
- )" ;
108
+ SECTION (" parentheses issue" )
109
+ {
110
+ auto doc = jsoncons::json::parse (R"(
111
+ {"foo" : [[0, 1], [2, 3], [4, 5]]}
112
+ )" );
99
113
100
- auto doc = ojson:: parse (jtext );
114
+ auto expected = jsoncons::json:: parse (R"( [0, 1] )" );
101
115
102
- auto result = jmespath::search (doc, expr);
116
+ std::string query = R"( (foo[*])[0])" ;
117
+ auto expr = jmespath::make_expression<jsoncons::json>(query);
103
118
104
- // std::cout << pretty_print(result) << "\n\n";
119
+ jsoncons::json result = expr.evaluate (doc);
120
+ // std::cout << pretty_print(result) << "\n";
121
+ CHECK (expected == result);
122
+ }
105
123
}
106
124
107
- TEST_CASE (" jmespath parentheses issue" )
125
+ TEST_CASE (" jmespath issue 605 " )
108
126
{
109
- auto doc = jsoncons::json::parse (R"(
110
- {"foo" : [[0, 1], [2, 3], [4, 5]]}
111
- )" );
112
-
113
- SECTION (" test 1" )
114
- {
115
- auto expected = jsoncons::json::parse (R"(
116
- [0, 1]
117
- )" );
127
+ SECTION (" function with 1 arg" )
128
+ {
129
+ std::string query = R"(
130
+ to_array("gw:GWallInfo"."gw:DocumentStatistics"."gw:ContentGroups"."gw:ContentGroup" ||
131
+ "gw:DocumentStatistics"."gw:ContentGroups"."gw:ContentGroup")
132
+ )" ;
133
+
134
+ auto expr = jsoncons::jmespath::make_expression<json>(query);
135
+ json j;
136
+ j[" gw:DocumentStatistics" ][" gw:ContentGroups" ][" gw:ContentGroup" ] = 9 ;
137
+ auto result = expr.evaluate (j);
138
+ REQUIRE (result.is_array ());
139
+ REQUIRE_FALSE (result.empty ());
140
+ CHECK (9 == result[0 ]);
141
+
142
+ // std::cout << pretty_print(result) << "\n\n";
143
+ }
144
+ SECTION (" function with 2 args" )
145
+ {
146
+ std::string query = R"( starts_with(B || A,null || 'a'))" ;
118
147
119
- std::string query = R"( (foo[*])[0])" ;
120
- auto expr = jmespath::make_expression<jsoncons::json>(query);
148
+ auto expr = jsoncons::jmespath::make_expression<json>(query);
149
+ json j;
150
+ j[" A" ] = " ab" ;
151
+ // auto result = jsoncons::jmespath::search(j, expr);
152
+ auto result = expr.evaluate (j);
153
+ // std::cout << result << "\n";
121
154
122
- jsoncons::json result = expr.evaluate (doc);
123
- // std::cout << pretty_print(result) << "\n";
124
- CHECK (expected == result);
125
- }
155
+ CHECK (result.as <bool >());
156
+ }
157
+ SECTION (" function with 2 args (2)" )
158
+ {
159
+ std::string query = R"( starts_with(A || B,null || 'a'))" ;
160
+
161
+ auto expr = jsoncons::jmespath::make_expression<json>(query);
162
+ json j;
163
+ j[" A" ] = " ab" ;
164
+ // auto result = jsoncons::jmespath::search(j, expr);
165
+ auto result = expr.evaluate (j);
166
+ // std::cout << result << "\n";
167
+
168
+ CHECK (result.as <bool >());
169
+ }
126
170
}
171
+
0 commit comments