@@ -41,8 +41,6 @@ public class JsonFunctionsTest {
41
41
public void json_valid_returns_false () {
42
42
List <LiteralExpression > expressions =
43
43
List .of (
44
- DSL .literal (LITERAL_MISSING ), // missing returns false
45
- DSL .literal (LITERAL_NULL ), // null returns false
46
44
DSL .literal ("invalid" ), // invalid type
47
45
DSL .literal ("{{[}}" ), // missing bracket
48
46
DSL .literal ("[}" ), // missing bracket
@@ -192,118 +190,6 @@ void json_returnsScalar() {
192
190
assertEquals (LITERAL_NULL , DSL .stringToJson (DSL .literal ("" )).valueOf ());
193
191
}
194
192
195
- @ Test
196
- void json_returnsSemanticCheckException () {
197
- List <LiteralExpression > expressions =
198
- List .of (
199
- DSL .literal ("invalid" ), // invalid type
200
- DSL .literal ("{{[}}" ), // missing bracket
201
- DSL .literal ("[}" ), // missing bracket
202
- DSL .literal ("}" ), // missing bracket
203
- DSL .literal ("\" missing quote" ), // missing quote
204
- DSL .literal ("abc" ), // not a type
205
- DSL .literal ("97ab" ), // not a type
206
- DSL .literal ("{1, 2, 3, 4}" ), // invalid object
207
- DSL .literal ("{123: 1, true: 2, null: 3}" ), // invalid object
208
- DSL .literal ("{\" invalid\" :\" json\" , \" string\" }" ), // invalid object
209
- DSL .literal ("[\" a\" : 1, \" b\" : 2]" ) // invalid array
210
- );
211
-
212
- expressions .stream ()
213
- .forEach (
214
- expr ->
215
- assertThrows (
216
- SemanticCheckException .class ,
217
- () -> DSL .castJson (expr ).valueOf (),
218
- "Expected to throw SemanticCheckException when calling castJson with " + expr ));
219
- }
220
-
221
- @ Test
222
- void json_returnsJsonObject () {
223
- FunctionExpression exp ;
224
-
225
- // Setup
226
- final String objectJson =
227
- "{\" foo\" : \" foo\" , \" fuzz\" : true, \" bar\" : 1234, \" bar2\" : 12.34, \" baz\" : null, "
228
- + "\" obj\" : {\" internal\" : \" value\" }, \" arr\" : [\" string\" , true, null]}" ;
229
-
230
- LinkedHashMap <String , ExprValue > objectMap = new LinkedHashMap <>();
231
- objectMap .put ("foo" , new ExprStringValue ("foo" ));
232
- objectMap .put ("fuzz" , ExprBooleanValue .of (true ));
233
- objectMap .put ("bar" , new ExprLongValue (1234 ));
234
- objectMap .put ("bar2" , new ExprDoubleValue (12.34 ));
235
- objectMap .put ("baz" , ExprNullValue .of ());
236
- objectMap .put (
237
- "obj" , ExprTupleValue .fromExprValueMap (Map .of ("internal" , new ExprStringValue ("value" ))));
238
- objectMap .put (
239
- "arr" ,
240
- new ExprCollectionValue (
241
- List .of (new ExprStringValue ("string" ), ExprBooleanValue .of (true ), ExprNullValue .of ())));
242
- ExprValue expectedTupleExpr = ExprTupleValue .fromExprValueMap (objectMap );
243
-
244
- // exercise
245
- exp = DSL .stringToJson (DSL .literal (objectJson ));
246
-
247
- // Verify
248
- var value = exp .valueOf ();
249
- assertTrue (value instanceof ExprTupleValue );
250
- assertEquals (expectedTupleExpr , value );
251
-
252
- // also test the empty object case
253
- assertEquals (
254
- ExprTupleValue .fromExprValueMap (Map .of ()), DSL .stringToJson (DSL .literal ("{}" )).valueOf ());
255
- }
256
-
257
- @ Test
258
- void json_returnsJsonArray () {
259
- FunctionExpression exp ;
260
-
261
- // Setup
262
- final String arrayJson = "[\" foo\" , \" fuzz\" , true, \" bar\" , 1234, 12.34, null]" ;
263
- ExprValue expectedArrayExpr =
264
- new ExprCollectionValue (
265
- List .of (
266
- new ExprStringValue ("foo" ),
267
- new ExprStringValue ("fuzz" ),
268
- LITERAL_TRUE ,
269
- new ExprStringValue ("bar" ),
270
- new ExprIntegerValue (1234 ),
271
- new ExprDoubleValue (12.34 ),
272
- LITERAL_NULL ));
273
-
274
- // exercise
275
- exp = DSL .stringToJson (DSL .literal (arrayJson ));
276
-
277
- // Verify
278
- var value = exp .valueOf ();
279
- assertTrue (value instanceof ExprCollectionValue );
280
- assertEquals (expectedArrayExpr , value );
281
-
282
- // also test the empty-array case
283
- assertEquals (new ExprCollectionValue (List .of ()), DSL .stringToJson (DSL .literal ("[]" )).valueOf ());
284
- }
285
-
286
- @ Test
287
- void json_returnsScalar () {
288
- assertEquals (
289
- new ExprStringValue ("foobar" ), DSL .stringToJson (DSL .literal ("\" foobar\" " )).valueOf ());
290
-
291
- assertEquals (new ExprIntegerValue (1234 ), DSL .stringToJson (DSL .literal ("1234" )).valueOf ());
292
-
293
- assertEquals (new ExprDoubleValue (12.34 ), DSL .stringToJson (DSL .literal ("12.34" )).valueOf ());
294
-
295
- assertEquals (LITERAL_TRUE , DSL .stringToJson (DSL .literal ("true" )).valueOf ());
296
- assertEquals (LITERAL_FALSE , DSL .stringToJson (DSL .literal ("false" )).valueOf ());
297
-
298
- assertEquals (LITERAL_NULL , DSL .stringToJson (DSL .literal ("null" )).valueOf ());
299
-
300
- assertEquals (LITERAL_NULL , DSL .stringToJson (DSL .literal (LITERAL_NULL )).valueOf ());
301
-
302
- assertEquals (LITERAL_MISSING , DSL .stringToJson (DSL .literal (LITERAL_MISSING )).valueOf ());
303
-
304
- assertEquals (LITERAL_NULL , DSL .stringToJson (DSL .literal ("" )).valueOf ());
305
- }
306
-
307
193
@ Test
308
194
void json_returnsSemanticCheckException () {
309
195
// invalid type
0 commit comments