|
1 | 1 | { |
2 | 2 | "source": "https://github.com/jsonquerylang/jsonquery/tree/main/test-suite/compile.test.json", |
3 | | - "updated": "2024-11-12T09:00:00Z", |
| 3 | + "updated": "2024-11-17T11:00:00Z", |
4 | 4 | "tests": [ |
| 5 | + { |
| 6 | + "category": "value", |
| 7 | + "description": "should get a string", |
| 8 | + "input": null, |
| 9 | + "query": "Hello", |
| 10 | + "output": "Hello" |
| 11 | + }, |
| 12 | + { |
| 13 | + "category": "value", |
| 14 | + "description": "should get a number", |
| 15 | + "input": null, |
| 16 | + "query": 2.4, |
| 17 | + "output": 2.4 |
| 18 | + }, |
| 19 | + { |
| 20 | + "category": "value", |
| 21 | + "description": "should get a boolean (true)", |
| 22 | + "input": null, |
| 23 | + "query": true, |
| 24 | + "output": true |
| 25 | + }, |
| 26 | + { |
| 27 | + "category": "value", |
| 28 | + "description": "should get a boolean (false)", |
| 29 | + "input": null, |
| 30 | + "query": false, |
| 31 | + "output": false |
| 32 | + }, |
| 33 | + { |
| 34 | + "category": "value", |
| 35 | + "description": "should get null", |
| 36 | + "input": null, |
| 37 | + "query": null, |
| 38 | + "output": null |
| 39 | + }, |
5 | 40 | { |
6 | 41 | "category": "pipe", |
7 | 42 | "description": "should execute a pipe (1)", |
8 | 43 | "input": [{ "user": { "name": "Joe" } }], |
9 | | - "query": ["pipe", ["get", "0"], ["get", "user"], ["get", "name"]], |
| 44 | + "query": ["pipe", ["get", 0], ["get", "user"], ["get", "name"]], |
10 | 45 | "output": "Joe" |
11 | 46 | }, |
12 | 47 | { |
|
98 | 133 | }, |
99 | 134 | { |
100 | 135 | "category": "get", |
101 | | - "description": "should return null in case of a non existing path", |
| 136 | + "description": "should return null in case of a non-existing path (1)", |
102 | 137 | "input": {}, |
103 | 138 | "query": ["get", "foo", "bar"], |
104 | 139 | "output": null |
105 | 140 | }, |
| 141 | + { |
| 142 | + "category": "get", |
| 143 | + "description": "should return null in case of a non-existing path (2)", |
| 144 | + "input": [1, 2, 3], |
| 145 | + "query": ["get", 5], |
| 146 | + "output": null |
| 147 | + }, |
106 | 148 | { |
107 | 149 | "category": "get", |
108 | 150 | "description": "should get a path using function get", |
|
147 | 189 | }, |
148 | 190 | { |
149 | 191 | "category": "get", |
150 | | - "description": "should get in item from an array (1)", |
| 192 | + "description": "should get an item from an array (1)", |
151 | 193 | "input": ["A", "B", "C"], |
152 | 194 | "query": ["get", 1], |
153 | 195 | "output": "B" |
154 | 196 | }, |
155 | 197 | { |
156 | 198 | "category": "get", |
157 | | - "description": "should get in item from an array (2)", |
| 199 | + "description": "should get an item from an array (2)", |
158 | 200 | "input": { "arr": ["A", "B", "C"] }, |
159 | 201 | "query": ["get", "arr", 1], |
160 | 202 | "output": "B" |
161 | 203 | }, |
162 | 204 | { |
163 | 205 | "category": "get", |
164 | | - "description": "should get in item from an array (3)", |
| 206 | + "description": "should get an item from an array (3)", |
165 | 207 | "input": [{ "text": "A" }, { "text": "B" }, { "text": "C" }], |
166 | 208 | "query": ["get", 1, "text"], |
167 | 209 | "output": "B" |
|
229 | 271 | "query": ["sort", ["get", "score"], "desc"], |
230 | 272 | "output": [{ "score": 5 }, { "score": 3 }, { "score": -2 }] |
231 | 273 | }, |
232 | | - { |
233 | | - "category": "sort", |
234 | | - "description": "should do nothing when sorting objects without a getter", |
235 | | - "input": [{ "a": 1 }, { "c": 3 }, { "b": 2 }], |
236 | | - "query": ["sort"], |
237 | | - "output": [{ "a": 1 }, { "c": 3 }, { "b": 2 }] |
238 | | - }, |
239 | 274 |
|
240 | 275 | { |
241 | 276 | "category": "pick", |
|
842 | 877 | }, |
843 | 878 | { |
844 | 879 | "category": "exists", |
845 | | - "description": "should calculate exists (1)", |
| 880 | + "description": "should calculate exists (2)", |
846 | 881 | "input": { "a": null }, |
847 | 882 | "query": ["exists", ["get", "a"]], |
848 | 883 | "output": true |
849 | 884 | }, |
850 | 885 | { |
851 | 886 | "category": "exists", |
852 | | - "description": "should calculate exists (1)", |
| 887 | + "description": "should calculate exists (3)", |
853 | 888 | "input": { "a": 2 }, |
854 | 889 | "query": ["exists", ["get", "a"]], |
855 | 890 | "output": true |
856 | 891 | }, |
857 | 892 | { |
858 | 893 | "category": "exists", |
859 | | - "description": "should calculate exists (1)", |
| 894 | + "description": "should calculate exists (4)", |
860 | 895 | "input": { "a": 0 }, |
861 | 896 | "query": ["exists", ["get", "a"]], |
862 | 897 | "output": true |
863 | 898 | }, |
864 | 899 | { |
865 | 900 | "category": "exists", |
866 | | - "description": "should calculate exists (1)", |
| 901 | + "description": "should calculate exists (5)", |
867 | 902 | "input": { "a": "" }, |
868 | 903 | "query": ["exists", ["get", "a"]], |
869 | 904 | "output": true |
870 | 905 | }, |
871 | 906 | { |
872 | 907 | "category": "exists", |
873 | | - "description": "should calculate exists (1)", |
| 908 | + "description": "should calculate exists (6)", |
874 | 909 | "input": { "nested": { "a": 2 } }, |
875 | 910 | "query": ["exists", ["get", "nested", "a"]], |
876 | 911 | "output": true |
877 | 912 | }, |
878 | 913 | { |
879 | 914 | "category": "exists", |
880 | | - "description": "should calculate exists (1)", |
| 915 | + "description": "should calculate exists (7)", |
881 | 916 | "input": {}, |
882 | 917 | "query": ["exists", ["get", "a"]], |
883 | 918 | "output": false |
884 | 919 | }, |
885 | 920 | { |
886 | 921 | "category": "exists", |
887 | | - "description": "should calculate exists (1)", |
| 922 | + "description": "should calculate exists (8)", |
888 | 923 | "input": {}, |
889 | 924 | "query": ["exists", ["get", "nested", "a"]], |
890 | 925 | "output": false |
891 | 926 | }, |
892 | 927 | { |
893 | 928 | "category": "exists", |
894 | | - "description": "should calculate exists (1)", |
| 929 | + "description": "should calculate exists (9)", |
895 | 930 | "input": {}, |
896 | 931 | "query": ["exists", ["get", "sort"]], |
897 | 932 | "output": false |
|
950 | 985 | "query": ["if", "", true, false], |
951 | 986 | "output": false |
952 | 987 | }, |
| 988 | + { |
| 989 | + "category": "if", |
| 990 | + "description": "should calculate if (8)", |
| 991 | + "input": null, |
| 992 | + "query": ["if", null, true, false], |
| 993 | + "output": false |
| 994 | + }, |
953 | 995 |
|
954 | 996 | { |
955 | 997 | "category": "in", |
|
1153 | 1195 | { |
1154 | 1196 | "category": "round", |
1155 | 1197 | "description": "should round a property to two digits", |
1156 | | - "input": { "a": 23.1345 }, |
| 1198 | + "input": { "a": 23.1348 }, |
1157 | 1199 | "query": ["round", ["get", "a"], 2], |
1158 | 1200 | "output": 23.13 |
1159 | 1201 | }, |
1160 | 1202 | { |
1161 | 1203 | "category": "round", |
1162 | 1204 | "description": "should round a property to three digits", |
1163 | | - "input": { "a": 23.1345 }, |
| 1205 | + "input": { "a": 23.1348 }, |
1164 | 1206 | "query": ["round", ["get", "a"], 3], |
1165 | 1207 | "output": 23.135 |
1166 | 1208 | }, |
1167 | 1209 | { |
1168 | 1210 | "category": "round", |
1169 | | - "description": "should round a number to three digits", |
| 1211 | + "description": "should round a number to two digits", |
1170 | 1212 | "input": null, |
1171 | | - "query": ["round", 23.1345, 2], |
| 1213 | + "query": ["round", 23.1348, 2], |
1172 | 1214 | "output": 23.13 |
1173 | 1215 | }, |
1174 | 1216 |
|
|
0 commit comments