From 0249399f06ab77c58e02698a6a0b2352f0dbf1ae Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Feb 2024 13:57:20 +0200 Subject: Add $json.object_names() function --- tests/function/json/testscript | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'tests/function') diff --git a/tests/function/json/testscript b/tests/function/json/testscript index 9f8c2e9..b7134a8 100644 --- a/tests/function/json/testscript +++ b/tests/function/json/testscript @@ -37,6 +37,31 @@ object object EOO +: size +: +$* <>EOO +print $value_size([json] null) +print $value_size([json] true) +print $value_size([json] 123) +print $value_size([json] abc) +print $size([string] ([json] abc)) # @@ Should be 3 (quoted, type hint). +print $value_size([json] 1 2 3) +print $value_size([json] one@1 two@2 three@3) + +print $array_size([json] 1 2 3) +print $array_size([json] null) +EOI +0 +1 +1 +1 +5 +3 +3 +3 +0 +EOO + : member : $* <>EOO @@ -55,24 +80,19 @@ two 2 three 3 EOO -: size +: names : $* <>EOO -print $value_size([json] null) -print $value_size([json] true) -print $value_size([json] 123) -print $value_size([json] abc) -print $size([string] ([json] abc)) # @@ Should be 3 (quoted, type hint). -print $value_size([json] 1 2 3) -print $value_size([json] one@1 two@2 three@3) +j = [json] one@1 two@2 three@3 +for n: $object_names($j) + print $n ($j[$n]) + +print $object_names([json] null) EOI -0 -1 -1 -1 -5 -3 -3 +one 1 +two 2 +three 3 + EOO : find @@ -92,6 +112,7 @@ print $array_find_index($j, [json] one@1) print $array_find_index($j, [json] one@1 two@2 three@3) print $array_find_index($j, [json] one@1 TWO@3) print $array_find_index($j, [json] one@1 two@3) +print $array_find_index([json] null, 1) EOI 5 3 @@ -106,6 +127,7 @@ EOI 11 11 11 +0 EOO : parse -- cgit v1.1