1 /* Include the C files directly. */
2 #include "ccan/graphql/graphql.c"
3 #include "ccan/str/str.h"
7 * The idea here is to run each test case silently, and if any test point
8 * fails, that test case is re-run verbosely to pinpoint the failure.
10 * RUN macros run a whole test case function.
12 * Different TEST_xxxx macros are provided for different test point types as
15 * TEST_CONT - Test and continue testing regardless of failure (the failure
16 * will still be printed).
17 * TEST_ABRT - Test and abort the test case, used when testing pointer
18 * validity to avoid subsequent dereference errors.
19 * TEST_STRG - Test a string value, which includes the convenience of testing
23 #define RUN(test) { prev_fail = fail; test(source); if (fail != prev_fail) { mute = false; test(source); mute = true; } }
24 #define RUN1(test,arg) { prev_fail = fail; test(source,arg); if (fail != prev_fail) { mute = false; test(source,arg); mute = true; } }
25 #define RUN2(test,arg1,arg2) { prev_fail = fail; test(source,arg1,arg2); if (fail != prev_fail) { mute = false; test(source,arg1,arg2); mute = true; } }
27 #define TEST_CONT(expr) { bool c = (expr); if (mute) c? pass++ : fail++; else printf("%s: %s\033[0m\n", c? "passed" : "\033[91mfailed", stringify(expr)); }
28 #define TEST_ABRT(expr) { bool c = (expr); if (mute) c? pass++ : fail++; else printf("%s: %s\033[0m\n", c? "passed" : "\033[91mfailed", stringify(expr)); if (!c) return; }
29 #define TEST_STRG(str,expr) { bool c = ((str) && streq((str),(expr))); if (mute) c? pass++ : fail++; else printf("%s: %s == %s\033[0m\n", c? "passed" : "\033[91mfailed", stringify(str), stringify(expr)); if (!c) return; }
31 // Global variables to track overall results.
32 int pass = 0, fail = 0;
36 int listlen(struct list_head *tokens);
37 int listlen(struct list_head *tokens) {
38 struct graphql_token *tok;
40 list_for_each(tokens, tok, node) {
46 /* Test case function prototypes */
48 void check_example_3(const char *source);
49 void check_example_5(char *source);
50 void check_example_6(char *source);
51 void check_example_7(char *source);
52 void check_example_8(char *source);
53 void check_example_9(char *source);
54 void check_example_10(char *source);
55 void check_example_11(char *source);
56 void check_example_12_and_13(const char *source);
57 void check_example_14(char *source);
58 void check_example_16(char *source);
59 void check_example_18(char *source);
60 void check_example_19(char *source);
61 void check_example_20(char *source);
62 void check_example_21(char *source);
63 void check_example_23(char *source);
64 void check_example_24(char *source);
65 void check_int_value(char *source, int int_value);
66 void check_invalid_int_values(char *source);
67 void check_float_value(char *source, float float_value, const char *format);
68 void check_valid_float_values(char *source);
69 void check_invalid_float_values(char *source);
70 void check_boolean_values(char *source);
71 void check_string_value(char *source, const char *test_value, const char *expected_result);
72 void check_example_25_and_26(const char *source);
73 void check_example_29(char *source);
74 void check_example_30_and_31(const char *source);
75 void check_example_32(char *source);
76 void check_example_34(char *source);
77 void check_example_35(char *source);
79 /* Test case functions begin here, called by main().
80 * Note: Memory should be freed correctly in the success case, but if there
81 * are errors, all bets are off.
84 void check_example_3(const char *source) {
85 struct list_head *tokens;
86 struct graphql_token *tok;
88 if (!mute) printf("// Example No. 3\n");
91 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
92 TEST_ABRT(listlen(tokens) == 11);
93 tok = list_pop(tokens, struct graphql_token, node);
94 TEST_CONT(tok->token_type == '{');
95 TEST_CONT(tok->source_line == 1);
96 TEST_CONT(tok->source_column == 1);
97 TEST_CONT(tok->source_len == 1);
98 tok = list_pop(tokens, struct graphql_token, node);
99 TEST_CONT(tok->token_type == 'a');
100 TEST_STRG(tok->token_string, "user");
101 TEST_CONT(tok->source_line == 2);
102 TEST_CONT(tok->source_column == 3);
103 TEST_CONT(tok->source_len == 4);
104 tok = list_pop(tokens, struct graphql_token, node);
105 TEST_CONT(tok->token_type == '(');
106 TEST_CONT(tok->source_line == 2);
107 TEST_CONT(tok->source_column == 7);
108 TEST_CONT(tok->source_len == 1);
109 tok = list_pop(tokens, struct graphql_token, node);
110 TEST_CONT(tok->token_type == 'a');
111 TEST_STRG(tok->token_string, "id");
112 TEST_CONT(tok->source_line == 2);
113 TEST_CONT(tok->source_column == 8);
114 TEST_CONT(tok->source_len == 2);
115 tok = list_pop(tokens, struct graphql_token, node);
116 TEST_CONT(tok->token_type == ':');
117 TEST_CONT(tok->source_line == 2);
118 TEST_CONT(tok->source_column == 10);
119 TEST_CONT(tok->source_len == 1);
120 tok = list_pop(tokens, struct graphql_token, node);
121 TEST_CONT(tok->token_type == 'i');
122 TEST_STRG(tok->token_string, "4");
123 TEST_CONT(tok->source_line == 2);
124 TEST_CONT(tok->source_column == 12);
125 TEST_CONT(tok->source_len == 1);
126 tok = list_pop(tokens, struct graphql_token, node);
127 TEST_CONT(tok->token_type == ')');
128 TEST_CONT(tok->source_line == 2);
129 TEST_CONT(tok->source_column == 13);
130 TEST_CONT(tok->source_len == 1);
131 tok = list_pop(tokens, struct graphql_token, node);
132 TEST_CONT(tok->token_type == '{');
133 TEST_CONT(tok->source_line == 2);
134 TEST_CONT(tok->source_column == 15);
135 TEST_CONT(tok->source_len == 1);
136 tok = list_pop(tokens, struct graphql_token, node);
137 TEST_CONT(tok->token_type == 'a');
138 TEST_STRG(tok->token_string, "name");
139 TEST_CONT(tok->source_line == 3);
140 TEST_CONT(tok->source_column == 5);
141 TEST_CONT(tok->source_len == 4);
142 tok = list_pop(tokens, struct graphql_token, node);
143 TEST_CONT(tok->token_type == '}');
144 TEST_CONT(tok->source_line == 4);
145 TEST_CONT(tok->source_column == 3);
146 TEST_CONT(tok->source_len == 1);
147 tok = list_pop(tokens, struct graphql_token, node);
148 TEST_CONT(tok->token_type == '}');
149 TEST_CONT(tok->source_line == 5);
150 TEST_CONT(tok->source_column == 1);
151 TEST_CONT(tok->source_len == 1);
152 tok = list_pop(tokens, struct graphql_token, node);
153 TEST_CONT(tok == NULL);
154 tokens = tal_free(tokens);
157 struct graphql_executable_document *doc;
158 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
159 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
160 TEST_ABRT(doc != NULL);
161 TEST_ABRT(doc->first_def != NULL);
162 TEST_CONT(doc->first_def->next_def == NULL);
163 TEST_CONT(doc->first_def->frag_def == NULL);
164 TEST_ABRT(doc->first_def->op_def != NULL);
165 TEST_CONT(doc->first_def->op_def->op_type == NULL);
166 TEST_CONT(doc->first_def->op_def->op_name == NULL);
167 TEST_CONT(doc->first_def->op_def->vars == NULL);
168 TEST_CONT(doc->first_def->op_def->directives == NULL);
169 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
170 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
171 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
172 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
173 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
174 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
175 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
176 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
177 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
178 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
179 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
180 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
181 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
182 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
183 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
184 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
185 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
186 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
187 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
188 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
189 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
190 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
191 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
192 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
193 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
194 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
195 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
196 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
197 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
198 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
199 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
200 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
201 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
202 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
203 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "name");
204 tokens = tal_free(tokens);
207 void check_example_5(char *source) {
208 struct list_head *tokens;
209 struct graphql_token *tok;
211 if (!mute) printf("// Example No. 5\n");
215 likeStory(storyID: 12345) {\n\
224 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
225 TEST_ABRT(listlen(tokens) == 15);
226 tok = list_pop(tokens, struct graphql_token, node);
227 TEST_CONT(tok->token_type == 'a');
228 TEST_STRG(tok->token_string, "mutation");
229 TEST_CONT(tok->source_line == 1);
230 TEST_CONT(tok->source_column == 1);
231 TEST_CONT(tok->source_len == 8);
232 tok = list_pop(tokens, struct graphql_token, node);
233 TEST_CONT(tok->token_type == '{');
234 tok = list_pop(tokens, struct graphql_token, node);
235 TEST_CONT(tok->token_type == 'a');
236 TEST_STRG(tok->token_string, "likeStory");
237 TEST_CONT(tok->source_line == 2);
238 TEST_CONT(tok->source_column == 3);
239 TEST_CONT(tok->source_len == 9);
240 tok = list_pop(tokens, struct graphql_token, node);
241 TEST_CONT(tok->token_type == '(');
242 tok = list_pop(tokens, struct graphql_token, node);
243 TEST_CONT(tok->token_type == 'a');
244 TEST_STRG(tok->token_string, "storyID");
245 TEST_CONT(tok->source_line == 2);
246 tok = list_pop(tokens, struct graphql_token, node);
247 TEST_CONT(tok->token_type == ':');
248 tok = list_pop(tokens, struct graphql_token, node);
249 TEST_CONT(tok->token_type == 'i');
250 TEST_STRG(tok->token_string, "12345");
251 TEST_CONT(tok->source_line == 2);
252 TEST_CONT(tok->source_column == 22);
253 TEST_CONT(tok->source_len == 5);
254 tok = list_pop(tokens, struct graphql_token, node);
255 TEST_CONT(tok->token_type == ')');
256 tok = list_pop(tokens, struct graphql_token, node);
257 TEST_CONT(tok->token_type == '{');
258 tok = list_pop(tokens, struct graphql_token, node);
259 TEST_CONT(tok->token_type == 'a');
260 TEST_STRG(tok->token_string, "story");
261 TEST_CONT(tok->source_line == 3);
262 tok = list_pop(tokens, struct graphql_token, node);
263 TEST_CONT(tok->token_type == '{');
264 tok = list_pop(tokens, struct graphql_token, node);
265 TEST_CONT(tok->token_type == 'a');
266 TEST_STRG(tok->token_string, "likeCount");
267 TEST_CONT(tok->source_line == 4);
268 tok = list_pop(tokens, struct graphql_token, node);
269 TEST_CONT(tok->token_type == '}');
270 tok = list_pop(tokens, struct graphql_token, node);
271 TEST_CONT(tok->token_type == '}');
272 tok = list_pop(tokens, struct graphql_token, node);
273 TEST_CONT(tok->token_type == '}');
274 tok = list_pop(tokens, struct graphql_token, node);
275 TEST_CONT(tok == NULL);
276 tokens = tal_free(tokens);
279 struct graphql_executable_document *doc;
280 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
281 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
282 TEST_ABRT(doc != NULL);
283 TEST_ABRT(doc->first_def != NULL);
284 TEST_CONT(doc->first_def->next_def == NULL);
285 TEST_CONT(doc->first_def->frag_def == NULL);
286 TEST_ABRT(doc->first_def->op_def != NULL);
287 TEST_ABRT(doc->first_def->op_def->op_type != NULL);
288 TEST_ABRT(doc->first_def->op_def->op_type->op_type != NULL);
289 TEST_CONT(doc->first_def->op_def->op_type->op_type->token_type == 'a');
290 TEST_STRG(doc->first_def->op_def->op_type->op_type->token_string, "mutation");
291 TEST_ABRT(doc->first_def->op_def->op_name == NULL);
292 TEST_CONT(doc->first_def->op_def->vars == NULL);
293 TEST_CONT(doc->first_def->op_def->directives == NULL);
294 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
295 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
296 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
297 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
298 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
299 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
300 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
301 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
302 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
303 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "likeStory");
304 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
305 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
306 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
307 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
308 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
309 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "storyID");
310 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
311 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
312 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
313 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
314 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "12345");
315 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
316 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
317 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
318 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
319 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
320 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
321 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
322 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
323 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
324 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
325 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
326 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
327 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "story");
328 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set != NULL);
329 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first != NULL);
330 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next == NULL);
331 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread == NULL);
332 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->inline_frag == NULL);
333 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field != NULL);
334 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->alias == NULL);
335 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->args == NULL);
336 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->directives == NULL);
337 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->sel_set == NULL);
338 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->name != NULL);
339 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
340 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field->name->token_string, "likeCount");
341 tokens = tal_free(tokens);
344 void check_example_6(char *source) {
345 struct list_head *tokens;
346 struct graphql_token *tok;
348 if (!mute) printf("// Example No. 6\n");
357 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
358 TEST_ABRT(listlen(tokens) == 3);
359 tok = list_pop(tokens, struct graphql_token, node);
360 TEST_CONT(tok->token_type == '{');
361 tok = list_pop(tokens, struct graphql_token, node);
362 TEST_CONT(tok->token_type == 'a');
363 TEST_STRG(tok->token_string, "field");
364 TEST_CONT(tok->source_line == 2);
365 TEST_CONT(tok->source_column == 3);
366 TEST_CONT(tok->source_len == 5);
367 tok = list_pop(tokens, struct graphql_token, node);
368 TEST_CONT(tok->token_type == '}');
369 tok = list_pop(tokens, struct graphql_token, node);
370 TEST_CONT(tok == NULL);
371 tokens = tal_free(tokens);
374 struct graphql_executable_document *doc;
375 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
376 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
377 TEST_ABRT(doc != NULL);
378 TEST_ABRT(doc->first_def != NULL);
379 TEST_CONT(doc->first_def->next_def == NULL);
380 TEST_CONT(doc->first_def->frag_def == NULL);
381 TEST_ABRT(doc->first_def->op_def != NULL);
382 TEST_CONT(doc->first_def->op_def->op_type == NULL);
383 TEST_ABRT(doc->first_def->op_def->op_name == NULL);
384 TEST_CONT(doc->first_def->op_def->vars == NULL);
385 TEST_CONT(doc->first_def->op_def->directives == NULL);
386 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
387 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
388 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
389 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
390 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
391 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
392 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
393 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
394 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
395 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "field");
396 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args == NULL);
397 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
398 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set == NULL);
399 tokens = tal_free(tokens);
402 void check_example_7(char *source) {
403 struct list_head *tokens;
404 struct graphql_token *tok;
406 if (!mute) printf("// Example No. 7\n");
417 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
418 TEST_ABRT(listlen(tokens) == 5);
419 tok = list_pop(tokens, struct graphql_token, node);
420 TEST_CONT(tok->token_type == '{');
421 tok = list_pop(tokens, struct graphql_token, node);
422 TEST_CONT(tok->token_type == 'a');
423 TEST_STRG(tok->token_string, "id");
424 TEST_CONT(tok->source_line == 2);
425 TEST_CONT(tok->source_column == 3);
426 TEST_CONT(tok->source_len == 2);
427 tok = list_pop(tokens, struct graphql_token, node);
428 TEST_CONT(tok->token_type == 'a');
429 TEST_STRG(tok->token_string, "firstName");
430 TEST_CONT(tok->source_line == 3);
431 TEST_CONT(tok->source_column == 3);
432 TEST_CONT(tok->source_len == 9);
433 tok = list_pop(tokens, struct graphql_token, node);
434 TEST_CONT(tok->token_type == 'a');
435 TEST_STRG(tok->token_string, "lastName");
436 TEST_CONT(tok->source_line == 4);
437 TEST_CONT(tok->source_column == 3);
438 TEST_CONT(tok->source_len == 8);
439 tok = list_pop(tokens, struct graphql_token, node);
440 TEST_CONT(tok->token_type == '}');
441 tok = list_pop(tokens, struct graphql_token, node);
442 TEST_CONT(tok == NULL);
443 tokens = tal_free(tokens);
446 struct graphql_executable_document *doc;
447 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
448 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
449 TEST_ABRT(doc != NULL);
450 TEST_ABRT(doc->first_def != NULL);
451 TEST_CONT(doc->first_def->next_def == NULL);
452 TEST_CONT(doc->first_def->frag_def == NULL);
453 TEST_ABRT(doc->first_def->op_def != NULL);
454 TEST_CONT(doc->first_def->op_def->op_type == NULL);
455 TEST_ABRT(doc->first_def->op_def->op_name == NULL);
456 TEST_CONT(doc->first_def->op_def->vars == NULL);
457 TEST_CONT(doc->first_def->op_def->directives == NULL);
458 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
459 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
460 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
461 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
462 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
463 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
464 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
465 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
466 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "id");
467 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args == NULL);
468 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
469 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set == NULL);
470 TEST_ABRT(doc->first_def->op_def->sel_set->first->next != NULL);
471 TEST_CONT(doc->first_def->op_def->sel_set->first->next->frag_spread == NULL);
472 TEST_CONT(doc->first_def->op_def->sel_set->first->next->inline_frag == NULL);
473 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->field != NULL);
474 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->alias == NULL);
475 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->field->name != NULL);
476 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->name->token_type == 'a');
477 TEST_STRG(doc->first_def->op_def->sel_set->first->next->field->name->token_string, "firstName");
478 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->args == NULL);
479 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->directives == NULL);
480 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->sel_set == NULL);
481 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->next != NULL);
482 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->frag_spread == NULL);
483 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->inline_frag == NULL);
484 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->next->field != NULL);
485 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->field->alias == NULL);
486 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->next->field->name != NULL);
487 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->field->name->token_type == 'a');
488 TEST_STRG(doc->first_def->op_def->sel_set->first->next->next->field->name->token_string, "lastName");
489 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->field->args == NULL);
490 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->field->directives == NULL);
491 TEST_CONT(doc->first_def->op_def->sel_set->first->next->next->field->sel_set == NULL);
492 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->next->next == NULL);
493 tokens = tal_free(tokens);
496 void check_example_8(char *source) {
497 struct list_head *tokens;
498 struct graphql_token *tok;
500 if (!mute) printf("// Example No. 8\n");
520 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
521 TEST_ABRT(listlen(tokens) == 17);
522 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
523 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
524 TEST_STRG(tok->token_string, "me");
525 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
526 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
527 TEST_STRG(tok->token_string, "id");
528 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
529 TEST_STRG(tok->token_string, "firstName");
530 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
531 TEST_STRG(tok->token_string, "lastName");
532 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
533 TEST_STRG(tok->token_string, "birthday");
534 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
535 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
536 TEST_STRG(tok->token_string, "month");
537 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
538 TEST_STRG(tok->token_string, "day");
539 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
540 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
541 TEST_STRG(tok->token_string, "friends");
542 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
543 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
544 TEST_STRG(tok->token_string, "name");
545 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
546 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
547 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
548 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
549 tokens = tal_free(tokens);
552 struct graphql_executable_document *doc;
553 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
554 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
555 TEST_ABRT(doc != NULL);
556 TEST_ABRT(doc->first_def != NULL);
557 TEST_CONT(doc->first_def->next_def == NULL);
558 TEST_CONT(doc->first_def->frag_def == NULL);
559 TEST_ABRT(doc->first_def->op_def != NULL);
560 TEST_CONT(doc->first_def->op_def->op_type == NULL);
561 TEST_ABRT(doc->first_def->op_def->op_name == NULL);
562 TEST_CONT(doc->first_def->op_def->vars == NULL);
563 TEST_CONT(doc->first_def->op_def->directives == NULL);
564 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
565 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
566 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
567 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
568 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
569 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
570 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
571 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
572 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
573 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "me");
574 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args == NULL);
575 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
576 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
577 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
578 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
579 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
580 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
581 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
582 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
583 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
584 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
585 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
586 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
587 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
588 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
589 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
590 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
591 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
592 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
593 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
594 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
595 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "firstName");
596 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
597 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
598 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
599 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
600 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
601 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
602 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field != NULL);
603 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias == NULL);
604 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name != NULL);
605 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_type == 'a');
606 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_string, "lastName");
607 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args == NULL);
608 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->directives == NULL);
609 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->sel_set == NULL);
610 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next != NULL);
611 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->frag_spread == NULL);
612 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->inline_frag == NULL);
613 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field != NULL);
614 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->alias == NULL);
615 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name != NULL);
616 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name->token_type == 'a');
617 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name->token_string, "birthday");
618 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args == NULL);
619 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->directives == NULL);
620 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set != NULL);
621 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first != NULL);
622 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field != NULL);
623 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->alias == NULL);
624 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->name != NULL);
625 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->name->token_type == 'a');
626 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->name->token_string, "month");
627 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->args == NULL);
628 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->directives == NULL);
629 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->field->sel_set == NULL);
630 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next != NULL);
631 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field != NULL);
632 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->alias == NULL);
633 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->name != NULL);
634 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->name->token_type == 'a');
635 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->name->token_string, "day");
636 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->args == NULL);
637 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->directives == NULL);
638 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->field->sel_set == NULL);
639 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set->first->next->next == NULL);
640 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next != NULL);
641 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->frag_spread == NULL);
642 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->inline_frag == NULL);
643 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field != NULL);
644 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->alias == NULL);
645 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->name != NULL);
646 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->name->token_type == 'a');
647 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->name->token_string, "friends");
648 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->args == NULL);
649 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->directives == NULL);
650 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set != NULL);
651 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first != NULL);
652 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field != NULL);
653 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->alias == NULL);
654 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->name != NULL);
655 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->name->token_type == 'a');
656 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->name->token_string, "name");
657 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->args == NULL);
658 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->directives == NULL);
659 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->field->sel_set == NULL);
660 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->field->sel_set->first->next == NULL);
661 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next->next == NULL);
662 tokens = tal_free(tokens);
665 void check_example_9(char *source) {
666 struct list_head *tokens;
667 struct graphql_token *tok;
669 if (!mute) printf("// Example No. 9\n");
672 # `me` could represent the currently logged in viewer.\n\
679 # `user` represents one of many users in a graph of data, referred to by a\n\
680 # unique identifier.\n\
689 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
690 TEST_ABRT(listlen(tokens) == 17);
691 // NOTE: Comments are ignored.
692 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
693 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
694 TEST_STRG(tok->token_string, "me");
695 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
696 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
697 TEST_STRG(tok->token_string, "name");
698 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
699 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
700 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
701 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
702 TEST_STRG(tok->token_string, "user");
703 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
704 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
705 TEST_STRG(tok->token_string, "id");
706 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
707 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
708 TEST_STRG(tok->token_string, "4");
709 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
710 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
711 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
712 TEST_STRG(tok->token_string, "name");
713 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
714 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
715 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
716 tokens = tal_free(tokens);
719 struct graphql_executable_document *doc;
720 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
721 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
722 TEST_ABRT(doc != NULL);
723 TEST_ABRT(doc->first_def != NULL);
724 TEST_ABRT(doc->first_def->next_def != NULL);
725 TEST_CONT(doc->first_def->frag_def == NULL);
726 TEST_ABRT(doc->first_def->op_def != NULL);
727 TEST_CONT(doc->first_def->op_def->op_type == NULL);
728 TEST_ABRT(doc->first_def->op_def->op_name == NULL);
729 TEST_CONT(doc->first_def->op_def->vars == NULL);
730 TEST_CONT(doc->first_def->op_def->directives == NULL);
731 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
732 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
733 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
734 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
735 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
736 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
737 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
738 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
739 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
740 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "me");
741 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args == NULL);
742 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
743 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
744 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
745 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
746 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
747 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
748 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
749 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
750 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
751 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
752 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "name");
753 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
754 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
755 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
756 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
757 TEST_CONT(doc->first_def->next_def->next_def == NULL);
758 TEST_CONT(doc->first_def->next_def->frag_def == NULL);
759 TEST_ABRT(doc->first_def->next_def->op_def != NULL);
760 TEST_CONT(doc->first_def->next_def->op_def->op_type == NULL);
761 TEST_CONT(doc->first_def->next_def->op_def->op_name == NULL);
762 TEST_CONT(doc->first_def->next_def->op_def->vars == NULL);
763 TEST_CONT(doc->first_def->next_def->op_def->directives == NULL);
764 TEST_ABRT(doc->first_def->next_def->op_def->sel_set != NULL);
765 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first != NULL);
766 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->next == NULL);
767 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->frag_spread == NULL);
768 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->inline_frag == NULL);
769 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field != NULL);
770 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->alias == NULL);
771 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->name != NULL);
772 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->name->token_type == 'a');
773 TEST_STRG(doc->first_def->next_def->op_def->sel_set->first->field->name->token_string, "user");
774 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args != NULL);
775 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args->first != NULL);
776 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->next == NULL);
777 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->name != NULL);
778 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
779 TEST_STRG(doc->first_def->next_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
780 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->val != NULL);
781 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
782 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
783 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
784 TEST_STRG(doc->first_def->next_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
785 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->directives == NULL);
786 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set != NULL);
787 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first != NULL);
788 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
789 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
790 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
791 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
792 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
793 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
794 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
795 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
796 TEST_ABRT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
797 TEST_CONT(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
798 TEST_STRG(doc->first_def->next_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "name");
799 tokens = tal_free(tokens);
802 void check_example_10(char *source) {
803 struct list_head *tokens;
804 struct graphql_token *tok;
806 if (!mute) printf("// Example No. 10\n");
813 profilePic(size: 100)\n\
819 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
820 TEST_ABRT(listlen(tokens) == 18);
821 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
822 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
823 TEST_STRG(tok->token_string, "user");
824 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
825 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
826 TEST_STRG(tok->token_string, "id");
827 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
828 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
829 TEST_STRG(tok->token_string, "4");
830 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
831 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
832 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
833 TEST_STRG(tok->token_string, "id");
834 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
835 TEST_STRG(tok->token_string, "name");
836 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
837 TEST_STRG(tok->token_string, "profilePic");
838 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
839 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
840 TEST_STRG(tok->token_string, "size");
841 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
842 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
843 TEST_STRG(tok->token_string, "100");
844 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
845 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
846 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
847 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
848 tokens = tal_free(tokens);
851 struct graphql_executable_document *doc;
852 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
853 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
854 TEST_ABRT(doc != NULL);
855 TEST_ABRT(doc->first_def != NULL);
856 TEST_CONT(doc->first_def->next_def == NULL);
857 TEST_CONT(doc->first_def->frag_def == NULL);
858 TEST_ABRT(doc->first_def->op_def != NULL);
859 TEST_CONT(doc->first_def->op_def->op_type == NULL);
860 TEST_CONT(doc->first_def->op_def->op_name == NULL);
861 TEST_CONT(doc->first_def->op_def->vars == NULL);
862 TEST_CONT(doc->first_def->op_def->directives == NULL);
863 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
864 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
865 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
866 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
867 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
868 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
869 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
870 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
871 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
872 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
873 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
874 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
875 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
876 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
877 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
878 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
879 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
880 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
881 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
882 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
883 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
884 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
885 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
886 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
887 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
888 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
889 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
890 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
891 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
892 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
893 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
894 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
895 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
896 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
897 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
898 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
899 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
900 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
901 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
902 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
903 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
904 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "name");
905 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
906 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
907 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
908 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
909 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
910 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
911 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
912 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field != NULL);
913 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias == NULL);
914 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name != NULL);
915 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_type == 'a');
916 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_string, "profilePic");
917 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->directives == NULL);
918 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->sel_set == NULL);
919 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args != NULL);
920 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first != NULL);
921 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next == NULL);
922 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name != NULL);
923 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_type == 'a');
924 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_string, "size");
925 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val != NULL);
926 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val != NULL);
927 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val != NULL);
928 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_type == 'i');
929 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_string, "100");
930 tokens = tal_free(tokens);
933 void check_example_11(char *source) {
934 struct list_head *tokens;
935 struct graphql_token *tok;
937 if (!mute) printf("// Example No. 11\n");
944 profilePic(width: 100, height: 50)\n\
950 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
951 TEST_ABRT(listlen(tokens) == 21);
952 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
953 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
954 TEST_STRG(tok->token_string, "user");
955 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
956 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
957 TEST_STRG(tok->token_string, "id");
958 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
959 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
960 TEST_STRG(tok->token_string, "4");
961 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
962 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
963 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
964 TEST_STRG(tok->token_string, "id");
965 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
966 TEST_STRG(tok->token_string, "name");
967 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
968 TEST_STRG(tok->token_string, "profilePic");
969 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
970 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
971 TEST_STRG(tok->token_string, "width");
972 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
973 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
974 TEST_STRG(tok->token_string, "100");
975 // NOTE: Comma is ignored.
976 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
977 TEST_STRG(tok->token_string, "height");
978 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
979 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
980 TEST_STRG(tok->token_string, "50");
981 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
982 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
983 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
984 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
985 tokens = tal_free(tokens);
988 struct graphql_executable_document *doc;
989 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
990 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
991 TEST_ABRT(doc != NULL);
992 TEST_ABRT(doc->first_def != NULL);
993 TEST_CONT(doc->first_def->next_def == NULL);
994 TEST_CONT(doc->first_def->frag_def == NULL);
995 TEST_ABRT(doc->first_def->op_def != NULL);
996 TEST_CONT(doc->first_def->op_def->op_type == NULL);
997 TEST_CONT(doc->first_def->op_def->op_name == NULL);
998 TEST_CONT(doc->first_def->op_def->vars == NULL);
999 TEST_CONT(doc->first_def->op_def->directives == NULL);
1000 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1001 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1002 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1003 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
1004 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
1005 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1006 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
1007 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
1008 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
1009 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
1010 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
1011 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
1012 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
1013 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
1014 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
1015 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
1016 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
1017 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
1018 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
1019 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
1020 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
1021 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
1022 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1023 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1024 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
1025 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
1026 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1027 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
1028 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
1029 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
1030 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
1031 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
1032 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
1033 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
1034 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1035 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
1036 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
1037 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1038 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
1039 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
1040 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
1041 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "name");
1042 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
1043 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
1044 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
1045 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
1046 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
1047 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
1048 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
1049 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field != NULL);
1050 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias == NULL);
1051 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name != NULL);
1052 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_type == 'a');
1053 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_string, "profilePic");
1054 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->directives == NULL);
1055 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->sel_set == NULL);
1056 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args != NULL);
1057 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first != NULL);
1058 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name != NULL);
1059 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_type == 'a');
1060 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_string, "width");
1061 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val != NULL);
1062 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val != NULL);
1063 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val != NULL);
1064 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_type == 'i');
1065 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_string, "100");
1066 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next != NULL);
1067 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->name != NULL);
1068 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->name->token_type == 'a');
1069 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->name->token_string, "height");
1070 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->val != NULL);
1071 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->val->int_val != NULL);
1072 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->val->int_val->val != NULL);
1073 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->val->int_val->val->token_type == 'i');
1074 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next->val->int_val->val->token_string, "50");
1075 tokens = tal_free(tokens);
1078 void check_example_12_and_13(const char *source) {
1079 struct list_head *tokens;
1080 struct graphql_token *tok;
1082 if (!mute) printf("// Example Nos. 12 and 13\n");
1086 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1087 TEST_ABRT(listlen(tokens) == 11);
1088 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1089 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1090 TEST_STRG(tok->token_string, "picture");
1091 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1092 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1093 TEST_ABRT(tok->token_string != NULL && (streq(tok->token_string, "width") || streq(tok->token_string, "height")));
1094 param = tok->token_string;
1095 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1096 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1097 TEST_CONT(tok->token_string != NULL && ((streq(param, "width") && streq(tok->token_string, "200")) || (streq(param, "height") && streq(tok->token_string, "100"))));
1098 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1099 TEST_CONT(tok->token_string != NULL && (streq(tok->token_string, "width") || streq(tok->token_string, "height")));
1100 param = tok->token_string;
1101 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1102 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1103 TEST_CONT(tok->token_string != NULL && ((streq(param, "width") && streq(tok->token_string, "200")) || (streq(param, "height") && streq(tok->token_string, "100"))));
1104 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1105 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1106 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
1107 tokens = tal_free(tokens);
1110 struct graphql_argument *arg;
1111 struct graphql_executable_document *doc;
1112 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1113 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
1114 TEST_ABRT(doc != NULL);
1115 TEST_ABRT(doc->first_def != NULL);
1116 TEST_CONT(doc->first_def->next_def == NULL);
1117 TEST_CONT(doc->first_def->frag_def == NULL);
1118 TEST_ABRT(doc->first_def->op_def != NULL);
1119 TEST_CONT(doc->first_def->op_def->op_type == NULL);
1120 TEST_CONT(doc->first_def->op_def->op_name == NULL);
1121 TEST_CONT(doc->first_def->op_def->vars == NULL);
1122 TEST_CONT(doc->first_def->op_def->directives == NULL);
1123 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1124 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1125 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1126 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
1127 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
1128 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1129 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
1130 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
1131 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
1132 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "picture");
1133 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
1134 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set == NULL);
1135 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
1136 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
1137 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->next != NULL);
1138 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next->next == NULL);
1139 arg = doc->first_def->op_def->sel_set->first->field->args->first;
1140 if (!streq(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "width")) arg = arg->next;
1141 TEST_ABRT(arg->name != NULL);
1142 TEST_CONT(arg->name->token_type == 'a');
1143 TEST_STRG(arg->name->token_string, "width");
1144 TEST_ABRT(arg->val != NULL);
1145 TEST_ABRT(arg->val->int_val != NULL);
1146 TEST_ABRT(arg->val->int_val->val != NULL);
1147 TEST_CONT(arg->val->int_val->val->token_type == 'i');
1148 TEST_STRG(arg->val->int_val->val->token_string, "200");
1149 arg = doc->first_def->op_def->sel_set->first->field->args->first;
1150 if (!streq(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "height")) arg = arg->next;
1151 TEST_ABRT(arg->name != NULL);
1152 TEST_CONT(arg->name->token_type == 'a');
1153 TEST_STRG(arg->name->token_string, "height");
1154 TEST_ABRT(arg->val != NULL);
1155 TEST_ABRT(arg->val->int_val != NULL);
1156 TEST_ABRT(arg->val->int_val->val != NULL);
1157 TEST_CONT(arg->val->int_val->val->token_type == 'i');
1158 TEST_STRG(arg->val->int_val->val->token_string, "100");
1159 tokens = tal_free(tokens);
1162 void check_example_14(char *source) {
1163 struct list_head *tokens;
1164 struct graphql_token *tok;
1166 if (!mute) printf("// Example No. 14\n");
1173 smallPic: profilePic(size: 64)\n\
1174 bigPic: profilePic(size: 1024)\n\
1180 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1181 TEST_ABRT(listlen(tokens) == 28);
1182 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1183 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1184 TEST_STRG(tok->token_string, "user");
1185 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1186 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1187 TEST_STRG(tok->token_string, "id");
1188 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1189 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1190 TEST_STRG(tok->token_string, "4");
1191 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1192 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1193 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1194 TEST_STRG(tok->token_string, "id");
1195 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1196 TEST_STRG(tok->token_string, "name");
1197 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1198 TEST_STRG(tok->token_string, "smallPic");
1199 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1200 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1201 TEST_STRG(tok->token_string, "profilePic");
1202 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1203 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1204 TEST_STRG(tok->token_string, "size");
1205 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1206 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1207 TEST_STRG(tok->token_string, "64");
1208 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1209 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1210 TEST_STRG(tok->token_string, "bigPic");
1211 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1212 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1213 TEST_STRG(tok->token_string, "profilePic");
1214 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1215 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1216 TEST_STRG(tok->token_string, "size");
1217 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1218 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1219 TEST_STRG(tok->token_string, "1024");
1220 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1221 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1222 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1223 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
1224 tokens = tal_free(tokens);
1227 struct graphql_executable_document *doc;
1228 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1229 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
1230 TEST_ABRT(doc != NULL);
1231 TEST_ABRT(doc->first_def != NULL);
1232 TEST_CONT(doc->first_def->next_def == NULL);
1233 TEST_CONT(doc->first_def->frag_def == NULL);
1234 TEST_ABRT(doc->first_def->op_def != NULL);
1235 TEST_CONT(doc->first_def->op_def->op_type == NULL);
1236 TEST_CONT(doc->first_def->op_def->op_name == NULL);
1237 TEST_CONT(doc->first_def->op_def->vars == NULL);
1238 TEST_CONT(doc->first_def->op_def->directives == NULL);
1239 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1240 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1241 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1242 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
1243 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
1244 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1245 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
1246 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
1247 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
1248 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
1249 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
1250 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
1251 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
1252 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
1253 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
1254 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
1255 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
1256 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
1257 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
1258 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
1259 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
1260 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
1261 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1262 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1263 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
1264 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
1265 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1266 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
1267 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
1268 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
1269 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
1270 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
1271 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
1272 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
1273 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1274 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
1275 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
1276 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1277 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
1278 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
1279 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
1280 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "name");
1281 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
1282 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
1283 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
1284 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
1285 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
1286 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
1287 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field != NULL);
1288 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias != NULL);
1289 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias->name != NULL);
1290 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias->name->token_type == 'a');
1291 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias->name->token_string, "smallPic");
1292 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name != NULL);
1293 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_type == 'a');
1294 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_string, "profilePic");
1295 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->directives == NULL);
1296 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->sel_set == NULL);
1297 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args != NULL);
1298 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first != NULL);
1299 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name != NULL);
1300 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_type == 'a');
1301 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_string, "size");
1302 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val != NULL);
1303 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val != NULL);
1304 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val != NULL);
1305 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_type == 'i');
1306 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->int_val->val->token_string, "64");
1307 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next == NULL);
1308 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next != NULL);
1309 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->next == NULL);
1310 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->frag_spread == NULL);
1311 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->inline_frag == NULL);
1312 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field != NULL);
1313 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->alias != NULL);
1314 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->alias->name != NULL);
1315 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->alias->name->token_type == 'a');
1316 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->alias->name->token_string, "bigPic");
1317 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name != NULL);
1318 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name->token_type == 'a');
1319 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->name->token_string, "profilePic");
1320 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->directives == NULL);
1321 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->sel_set == NULL);
1322 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args != NULL);
1323 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first != NULL);
1324 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->name != NULL);
1325 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->name->token_type == 'a');
1326 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->name->token_string, "size");
1327 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->val != NULL);
1328 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->val->int_val != NULL);
1329 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->val->int_val->val != NULL);
1330 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->val->int_val->val->token_type == 'i');
1331 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->val->int_val->val->token_string, "1024");
1332 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next->field->args->first->next == NULL);
1333 tokens = tal_free(tokens);
1336 void check_example_16(char *source) {
1337 struct list_head *tokens;
1338 struct graphql_token *tok;
1340 if (!mute) printf("// Example No. 16\n");
1344 zuck: user(id: 4) {\n\
1352 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1353 TEST_ABRT(listlen(tokens) == 14);
1354 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1355 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1356 TEST_STRG(tok->token_string, "zuck");
1357 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1358 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1359 TEST_STRG(tok->token_string, "user");
1360 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1361 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1362 TEST_STRG(tok->token_string, "id");
1363 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1364 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
1365 TEST_STRG(tok->token_string, "4");
1366 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1367 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1368 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1369 TEST_STRG(tok->token_string, "id");
1370 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1371 TEST_STRG(tok->token_string, "name");
1372 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1373 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1374 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
1375 tokens = tal_free(tokens);
1378 struct graphql_executable_document *doc;
1379 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1380 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
1381 TEST_ABRT(doc != NULL);
1382 TEST_ABRT(doc->first_def != NULL);
1383 TEST_CONT(doc->first_def->next_def == NULL);
1384 TEST_CONT(doc->first_def->frag_def == NULL);
1385 TEST_ABRT(doc->first_def->op_def != NULL);
1386 TEST_CONT(doc->first_def->op_def->op_type == NULL);
1387 TEST_CONT(doc->first_def->op_def->op_name == NULL);
1388 TEST_CONT(doc->first_def->op_def->vars == NULL);
1389 TEST_CONT(doc->first_def->op_def->directives == NULL);
1390 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1391 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1392 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1393 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
1394 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
1395 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1396 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->alias != NULL);
1397 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->alias->name != NULL);
1398 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias->name->token_type == 'a');
1399 TEST_STRG(doc->first_def->op_def->sel_set->first->field->alias->name->token_string, "zuck");
1400 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
1401 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
1402 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
1403 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
1404 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
1405 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
1406 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
1407 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
1408 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
1409 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
1410 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
1411 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
1412 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
1413 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
1414 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
1415 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1416 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1417 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
1418 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
1419 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1420 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
1421 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
1422 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
1423 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
1424 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
1425 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
1426 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
1427 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1428 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
1429 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
1430 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1431 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
1432 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
1433 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
1434 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "name");
1435 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
1436 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
1437 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
1438 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next == NULL);
1439 tokens = tal_free(tokens);
1442 void check_example_18(char *source) {
1443 struct list_head *tokens;
1445 if (!mute) printf("// Example No. 18\n");
1448 query noFragments {\n\
1450 friends(first: 10) {\n\
1453 profilePic(size: 50)\n\
1455 mutualFriends(first: 10) {\n\
1458 profilePic(size: 50)\n\
1465 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1466 TEST_ABRT(listlen(tokens) == 44);
1467 tokens = tal_free(tokens);
1470 struct graphql_executable_document *doc;
1471 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1472 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
1473 TEST_ABRT(doc != NULL);
1474 TEST_ABRT(doc->first_def != NULL);
1475 TEST_ABRT(doc->first_def->op_def != NULL);
1476 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1477 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1478 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1479 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1480 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1481 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1482 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1483 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set != NULL);
1484 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first != NULL);
1485 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next != NULL);
1486 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next->next != NULL);
1487 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next->next->next == NULL);
1488 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1489 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1490 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set != NULL);
1491 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first != NULL);
1492 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->next != NULL);
1493 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->next->next != NULL);
1494 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->next->next->next == NULL);
1495 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next == NULL);
1496 tokens = tal_free(tokens);
1499 void check_example_19(char *source) {
1500 struct list_head *tokens;
1501 struct graphql_token *tok;
1503 if (!mute) printf("// Example No. 19\n");
1506 query withFragments {\n\
1508 friends(first: 10) {\n\
1511 mutualFriends(first: 10) {\n\
1517 fragment friendFields on User {\n\
1520 profilePic(size: 50)\n\
1525 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1526 TEST_ABRT(listlen(tokens) == 46);
1527 for (int i=0; i<17; i++)
1528 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1529 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 0x2026);
1530 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1531 TEST_STRG(tok->token_string, "friendFields");
1532 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1533 for (int i=0; i<7; i++)
1534 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1535 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 0x2026);
1536 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1537 TEST_STRG(tok->token_string, "friendFields");
1538 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1539 tokens = tal_free(tokens);
1542 struct graphql_executable_document *doc;
1544 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1545 TEST_CONT((e = graphql_parse(tokens, &doc)) == NULL);
1546 if (e) printf("%s\n", e);
1547 TEST_ABRT(doc != NULL);
1548 TEST_ABRT(doc->first_def != NULL);
1549 TEST_ABRT(doc->first_def->op_def != NULL);
1550 TEST_CONT(doc->first_def->frag_def == NULL);
1551 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1552 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1553 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1554 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1555 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1556 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1557 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1558 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set != NULL);
1559 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first != NULL);
1560 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next == NULL);
1561 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field == NULL);
1562 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->inline_frag == NULL);
1563 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread != NULL);
1564 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->directives == NULL);
1565 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name != NULL);
1566 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name != NULL);
1567 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name->token_type == 'a');
1568 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name->token_string, "friendFields");
1569 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1570 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1571 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set != NULL);
1572 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first != NULL);
1573 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->next == NULL);
1574 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->field == NULL);
1575 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->inline_frag == NULL);
1576 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread != NULL);
1577 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->directives == NULL);
1578 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name != NULL);
1579 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name != NULL);
1580 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name->token_type == 'a');
1581 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name->token_string, "friendFields");
1582 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next == NULL);
1583 TEST_ABRT(doc->first_def->next_def != NULL);
1584 TEST_CONT(doc->first_def->next_def->next_def == NULL);
1585 TEST_CONT(doc->first_def->next_def->op_def == NULL);
1586 TEST_ABRT(doc->first_def->next_def->frag_def != NULL);
1587 TEST_ABRT(doc->first_def->next_def->frag_def->name != NULL);
1588 TEST_ABRT(doc->first_def->next_def->frag_def->name->name != NULL);
1589 TEST_CONT(doc->first_def->next_def->frag_def->name->name->token_type == 'a');
1590 TEST_STRG(doc->first_def->next_def->frag_def->name->name->token_string, "friendFields");
1591 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond != NULL);
1592 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type != NULL);
1593 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type->name != NULL);
1594 TEST_CONT(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_type == 'a');
1595 TEST_STRG(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_string, "User");
1596 TEST_CONT(doc->first_def->next_def->frag_def->directives == NULL);
1597 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set != NULL);
1598 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first != NULL);
1599 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next != NULL);
1600 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->next != NULL);
1601 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->next->next == NULL);
1602 tokens = tal_free(tokens);
1605 void check_example_20(char *source) {
1606 struct list_head *tokens;
1607 struct graphql_token *tok;
1609 if (!mute) printf("// Example No. 20\n");
1612 query withNestedFragments {\n\
1614 friends(first: 10) {\n\
1617 mutualFriends(first: 10) {\n\
1623 fragment friendFields on User {\n\
1626 ...standardProfilePic\n\
1629 fragment standardProfilePic on User {\n\
1630 profilePic(size: 50)\n\
1635 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1636 TEST_ABRT(listlen(tokens) == 54);
1637 for (int i=0; i<17; i++)
1638 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1639 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 0x2026);
1640 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1641 TEST_STRG(tok->token_string, "friendFields");
1642 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1643 for (int i=0; i<7; i++)
1644 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1645 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 0x2026);
1646 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1647 TEST_STRG(tok->token_string, "friendFields");
1648 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
1649 tokens = tal_free(tokens);
1652 struct graphql_executable_document *doc;
1654 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1655 TEST_CONT((e = graphql_parse(tokens, &doc)) == NULL);
1656 if (e) printf("%s\n", e);
1657 TEST_ABRT(doc != NULL);
1658 TEST_ABRT(doc->first_def != NULL);
1659 TEST_ABRT(doc->first_def->op_def != NULL);
1660 TEST_CONT(doc->first_def->frag_def == NULL);
1661 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1662 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1663 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1664 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1665 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1666 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1667 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1668 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set != NULL);
1669 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first != NULL);
1670 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->next == NULL);
1671 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->field == NULL);
1672 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->inline_frag == NULL);
1673 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread != NULL);
1674 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->directives == NULL);
1675 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name != NULL);
1676 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name != NULL);
1677 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name->token_type == 'a');
1678 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set->first->frag_spread->name->name->token_string, "friendFields");
1679 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1680 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
1681 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set != NULL);
1682 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first != NULL);
1683 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->next == NULL);
1684 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->field == NULL);
1685 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->inline_frag == NULL);
1686 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread != NULL);
1687 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->directives == NULL);
1688 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name != NULL);
1689 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name != NULL);
1690 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name->token_type == 'a');
1691 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set->first->frag_spread->name->name->token_string, "friendFields");
1692 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next == NULL);
1693 TEST_ABRT(doc->first_def->next_def != NULL);
1694 TEST_CONT(doc->first_def->next_def->op_def == NULL);
1695 TEST_ABRT(doc->first_def->next_def->frag_def != NULL);
1696 TEST_ABRT(doc->first_def->next_def->frag_def->name != NULL);
1697 TEST_ABRT(doc->first_def->next_def->frag_def->name->name != NULL);
1698 TEST_CONT(doc->first_def->next_def->frag_def->name->name->token_type == 'a');
1699 TEST_STRG(doc->first_def->next_def->frag_def->name->name->token_string, "friendFields");
1700 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond != NULL);
1701 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type != NULL);
1702 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type->name != NULL);
1703 TEST_CONT(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_type == 'a');
1704 TEST_STRG(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_string, "User");
1705 TEST_CONT(doc->first_def->next_def->frag_def->directives == NULL);
1706 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set != NULL);
1707 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first != NULL);
1708 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->field != NULL);
1709 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->frag_spread == NULL);
1710 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->inline_frag == NULL);
1711 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next != NULL);
1712 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->field != NULL);
1713 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->next->frag_spread == NULL);
1714 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->next->inline_frag == NULL);
1715 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->next != NULL);
1716 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->next->next->field == NULL);
1717 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->next->frag_spread != NULL);
1718 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->next->next->inline_frag == NULL);
1719 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next->next->next == NULL);
1720 TEST_ABRT(doc->first_def->next_def->next_def != NULL);
1721 TEST_CONT(doc->first_def->next_def->next_def->next_def == NULL);
1722 TEST_CONT(doc->first_def->next_def->next_def->op_def == NULL);
1723 TEST_ABRT(doc->first_def->next_def->next_def->frag_def != NULL);
1724 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->name != NULL);
1725 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->name->name != NULL);
1726 TEST_CONT(doc->first_def->next_def->next_def->frag_def->name->name->token_type == 'a');
1727 TEST_STRG(doc->first_def->next_def->next_def->frag_def->name->name->token_string, "standardProfilePic");
1728 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond != NULL);
1729 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type != NULL);
1730 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name != NULL);
1731 TEST_CONT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name->token_type == 'a');
1732 TEST_STRG(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name->token_string, "User");
1733 TEST_CONT(doc->first_def->next_def->next_def->frag_def->directives == NULL);
1734 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->sel_set != NULL);
1735 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->sel_set->first != NULL);
1736 TEST_CONT(doc->first_def->next_def->next_def->frag_def->sel_set->first->next == NULL);
1737 tokens = tal_free(tokens);
1740 void check_example_21(char *source) {
1741 struct list_head *tokens;
1742 struct graphql_token *tok;
1744 if (!mute) printf("// Example No. 21\n");
1747 query FragmentTyping {\n\
1748 profiles(handles: [\"zuck\", \"coca-cola\"]) {\n\
1755 fragment userFragment on User {\n\
1761 fragment pageFragment on Page {\n\
1769 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1770 TEST_ABRT(listlen(tokens) == 40);
1771 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1772 TEST_STRG(tok->token_string, "query");
1773 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1774 TEST_STRG(tok->token_string, "FragmentTyping");
1775 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1776 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1777 TEST_STRG(tok->token_string, "profiles");
1778 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1779 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1780 TEST_STRG(tok->token_string, "handles");
1781 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1782 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '[');
1783 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
1784 TEST_STRG(tok->token_string, "zuck");
1785 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
1786 TEST_STRG(tok->token_string, "coca-cola");
1787 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ']');
1788 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1789 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1790 tokens = tal_free(tokens);
1793 struct graphql_executable_document *doc;
1795 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1796 TEST_CONT((e = graphql_parse(tokens, &doc)) == NULL);
1797 if (e) printf("%s\n", e);
1798 TEST_ABRT(doc != NULL);
1799 TEST_ABRT(doc->first_def != NULL);
1800 TEST_ABRT(doc->first_def->op_def != NULL);
1801 TEST_CONT(doc->first_def->frag_def == NULL);
1802 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1803 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1804 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1805 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1806 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1807 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1808 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1809 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
1810 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
1811 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
1812 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1813 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field == NULL);
1814 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread != NULL);
1815 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread->name != NULL);
1816 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread->name->name != NULL);
1817 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread->name->name->token_type == 'a');
1818 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread->name->name->token_string, "userFragment");
1819 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
1820 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
1821 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field == NULL);
1822 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread != NULL);
1823 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread->name != NULL);
1824 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread->name->name != NULL);
1825 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread->name->name->token_type == 'a');
1826 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread->name->name->token_string, "pageFragment");
1827 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
1828 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
1829 TEST_ABRT(doc->first_def->next_def != NULL);
1830 TEST_CONT(doc->first_def->next_def->op_def == NULL);
1831 TEST_ABRT(doc->first_def->next_def->frag_def != NULL);
1832 TEST_ABRT(doc->first_def->next_def->frag_def->name != NULL);
1833 TEST_ABRT(doc->first_def->next_def->frag_def->name->name != NULL);
1834 TEST_CONT(doc->first_def->next_def->frag_def->name->name->token_type == 'a');
1835 TEST_STRG(doc->first_def->next_def->frag_def->name->name->token_string, "userFragment");
1836 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond != NULL);
1837 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type != NULL);
1838 TEST_ABRT(doc->first_def->next_def->frag_def->type_cond->named_type->name != NULL);
1839 TEST_CONT(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_type == 'a');
1840 TEST_STRG(doc->first_def->next_def->frag_def->type_cond->named_type->name->token_string, "User");
1841 TEST_CONT(doc->first_def->next_def->frag_def->directives == NULL);
1842 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set != NULL);
1843 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first != NULL);
1844 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->field != NULL);
1845 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->frag_spread == NULL);
1846 TEST_CONT(doc->first_def->next_def->frag_def->sel_set->first->inline_frag == NULL);
1847 TEST_ABRT(doc->first_def->next_def->frag_def->sel_set->first->next == NULL);
1848 TEST_ABRT(doc->first_def->next_def->next_def != NULL);
1849 TEST_CONT(doc->first_def->next_def->next_def->next_def == NULL);
1850 TEST_CONT(doc->first_def->next_def->next_def->op_def == NULL);
1851 TEST_ABRT(doc->first_def->next_def->next_def->frag_def != NULL);
1852 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->name != NULL);
1853 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->name->name != NULL);
1854 TEST_CONT(doc->first_def->next_def->next_def->frag_def->name->name->token_type == 'a');
1855 TEST_STRG(doc->first_def->next_def->next_def->frag_def->name->name->token_string, "pageFragment");
1856 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond != NULL);
1857 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type != NULL);
1858 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name != NULL);
1859 TEST_CONT(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name->token_type == 'a');
1860 TEST_STRG(doc->first_def->next_def->next_def->frag_def->type_cond->named_type->name->token_string, "Page");
1861 TEST_CONT(doc->first_def->next_def->next_def->frag_def->directives == NULL);
1862 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->sel_set != NULL);
1863 TEST_ABRT(doc->first_def->next_def->next_def->frag_def->sel_set->first != NULL);
1864 TEST_CONT(doc->first_def->next_def->next_def->frag_def->sel_set->first->next == NULL);
1865 tokens = tal_free(tokens);
1868 void check_example_23(char *source) {
1869 struct list_head *tokens;
1870 struct graphql_token *tok;
1872 if (!mute) printf("// Example No. 23\n");
1875 query inlineFragmentTyping {\n\
1876 profiles(handles: [\"zuck\", \"coca-cola\"]) {\n\
1893 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1894 TEST_ABRT(listlen(tokens) == 34);
1895 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1896 TEST_STRG(tok->token_string, "query");
1897 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1898 TEST_STRG(tok->token_string, "inlineFragmentTyping");
1899 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1900 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1901 TEST_STRG(tok->token_string, "profiles");
1902 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1903 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1904 TEST_STRG(tok->token_string, "handles");
1905 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
1906 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '[');
1907 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
1908 TEST_STRG(tok->token_string, "zuck");
1909 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
1910 TEST_STRG(tok->token_string, "coca-cola");
1911 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ']');
1912 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
1913 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
1914 tokens = tal_free(tokens);
1917 struct graphql_executable_document *doc;
1919 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1920 TEST_CONT((e = graphql_parse(tokens, &doc)) == NULL);
1921 if (e) printf("%s\n", e);
1922 TEST_ABRT(doc != NULL);
1923 TEST_ABRT(doc->first_def != NULL);
1924 TEST_ABRT(doc->first_def->op_def != NULL);
1925 TEST_CONT(doc->first_def->frag_def == NULL);
1926 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
1927 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
1928 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
1929 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
1930 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
1931 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
1932 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
1933 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
1934 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
1935 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
1936 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
1937 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field == NULL);
1938 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
1939 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag != NULL);
1940 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->directives == NULL);
1941 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->type_cond != NULL);
1942 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->type_cond->named_type->name != NULL);
1943 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->type_cond->named_type->name->token_type == 'a');
1944 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->type_cond->named_type->name->token_string, "User");
1945 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set != NULL);
1946 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set->first != NULL);
1947 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set->first->field != NULL);
1948 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set->first->frag_spread == NULL);
1949 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set->first->inline_frag == NULL);
1950 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag->sel_set->first->next == NULL);
1951 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
1952 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field == NULL);
1953 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
1954 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag != NULL);
1955 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives == NULL);
1956 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->type_cond != NULL);
1957 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->type_cond->named_type->name != NULL);
1958 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->type_cond->named_type->name->token_type == 'a');
1959 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->type_cond->named_type->name->token_string, "Page");
1960 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set != NULL);
1961 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first != NULL);
1962 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->field != NULL);
1963 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->frag_spread == NULL);
1964 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->inline_frag == NULL);
1965 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->next == NULL);
1966 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
1967 TEST_CONT(doc->first_def->next_def == NULL);
1968 tokens = tal_free(tokens);
1971 void check_example_24(char *source) {
1972 struct list_head *tokens;
1973 struct graphql_token *tok;
1975 if (!mute) printf("// Example No. 24\n");
1978 query inlineFragmentNoType($expandedInfo: Boolean) {\n\
1979 user(handle: \"zuck\") {\n\
1982 ... @include(if: $expandedInfo) {\n\
1992 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
1993 TEST_ABRT(listlen(tokens) == 34);
1994 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1995 TEST_STRG(tok->token_string, "query");
1996 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
1997 TEST_STRG(tok->token_string, "inlineFragmentNoType");
1998 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
1999 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '$');
2000 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2001 TEST_STRG(tok->token_string, "expandedInfo");
2002 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2003 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2004 TEST_STRG(tok->token_string, "Boolean");
2005 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2006 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2007 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2008 TEST_STRG(tok->token_string, "user");
2009 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2010 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2011 TEST_STRG(tok->token_string, "handle");
2012 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2013 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2014 TEST_STRG(tok->token_string, "zuck");
2015 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2016 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2017 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2018 TEST_STRG(tok->token_string, "id");
2019 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2020 TEST_STRG(tok->token_string, "name");
2021 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 0x2026);
2022 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '@');
2023 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2024 TEST_STRG(tok->token_string, "include");
2025 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2026 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2027 TEST_STRG(tok->token_string, "if");
2028 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2029 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '$');
2030 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2031 TEST_STRG(tok->token_string, "expandedInfo");
2032 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2033 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2034 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2035 TEST_STRG(tok->token_string, "firstName");
2036 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2037 TEST_STRG(tok->token_string, "lastName");
2038 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2039 TEST_STRG(tok->token_string, "birthday");
2040 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2041 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2042 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2043 tokens = tal_free(tokens);
2046 struct graphql_executable_document *doc;
2047 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2048 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2049 TEST_ABRT(doc != NULL);
2050 TEST_ABRT(doc->first_def != NULL);
2051 TEST_ABRT(doc->first_def->op_def != NULL);
2052 TEST_CONT(doc->first_def->frag_def == NULL);
2053 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2054 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2055 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2056 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2057 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2058 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2059 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2060 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
2061 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
2062 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
2063 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
2064 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
2065 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
2066 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
2067 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
2068 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field == NULL);
2069 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
2070 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag != NULL);
2071 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->type_cond == NULL);
2072 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives != NULL);
2073 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first != NULL);
2074 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->next == NULL);
2075 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->name != NULL);
2076 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->name->token_type == 'a');
2077 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->name->token_string, "include");
2078 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args != NULL);
2079 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first != NULL);
2080 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->next == NULL);
2081 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->name != NULL);
2082 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->name->token_type == 'a');
2083 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->name->token_string, "if");
2084 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val != NULL);
2085 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->int_val == NULL);
2086 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->float_val == NULL);
2087 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->bool_val == NULL);
2088 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->str_val == NULL);
2089 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->null_val == NULL);
2090 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->enum_val == NULL);
2091 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->list_val == NULL);
2092 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->obj_val == NULL);
2093 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->var != NULL);
2094 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->var->name != NULL);
2095 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->var->name->token_type == 'a');
2096 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->directives->first->args->first->val->var->name->token_string, "expandedInfo");
2097 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set != NULL);
2098 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first != NULL);
2099 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->field != NULL);
2100 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->frag_spread == NULL);
2101 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->inline_frag == NULL);
2102 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->next != NULL);
2103 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->next->next != NULL);
2104 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag->sel_set->first->next->next->next == NULL);
2105 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
2106 TEST_CONT(doc->first_def->next_def == NULL);
2107 tokens = tal_free(tokens);
2110 void check_int_value(char *source, int int_value) {
2111 struct list_head *tokens;
2112 struct graphql_token *tok;
2114 if (!mute) printf("// Int Value Range Check on %d\n", int_value);
2125 sprintf(buf, "%d", int_value);
2128 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2129 TEST_ABRT(listlen(tokens) == 11);
2130 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2131 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2132 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2133 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2134 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2135 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
2136 TEST_STRG(tok->token_string, buf);
2137 TEST_CONT(tok->source_line == 2);
2138 TEST_CONT(tok->source_column == 12);
2139 TEST_CONT(tok->source_len == strlen(buf));
2140 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2141 TEST_CONT(tok->source_line == 2);
2142 TEST_CONT(tok->source_column == 12 + strlen(buf));
2143 TEST_CONT(tok->source_len == 1);
2144 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2145 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2146 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2147 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2148 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2149 tokens = tal_free(tokens);
2152 struct graphql_executable_document *doc;
2153 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2154 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2155 TEST_ABRT(doc != NULL);
2156 TEST_ABRT(doc->first_def != NULL);
2157 TEST_ABRT(doc->first_def->op_def != NULL);
2158 TEST_CONT(doc->first_def->next_def == NULL);
2159 TEST_CONT(doc->first_def->frag_def == NULL);
2160 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2161 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2162 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2163 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2164 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2165 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2166 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2167 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2168 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
2169 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
2170 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
2171 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, buf);
2172 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2173 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2174 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2175 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2176 tokens = tal_free(tokens);
2179 void check_invalid_int_values(char *source) {
2180 struct list_head *tokens;
2182 if (!mute) printf("// Invalid Int Values\n");
2184 const char *bad_values[] = {"00", "-00", "+1", "1.", "1a", "1e", "0x123", "123L", 0};
2186 for (int i=0; bad_values[i]; i++) {
2196 TEST_CONT(graphql_lex(NULL, source, &tokens) != NULL);
2197 TEST_ABRT(listlen(tokens) == 5);
2198 tokens = tal_free(tokens);
2200 // No need to test parser when lexer fails.
2204 void check_float_value(char *source, float float_value, const char *format) {
2205 struct list_head *tokens;
2206 struct graphql_token *tok;
2208 if (!mute) printf("// Float Value Range Check on %f\n", float_value);
2218 sprintf(source, buf, float_value);
2219 sprintf(buf, format, float_value);
2222 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2223 TEST_ABRT(listlen(tokens) == 11);
2224 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2225 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2226 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2227 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2228 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2229 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'f');
2230 TEST_STRG(tok->token_string, buf);
2231 TEST_CONT(tok->source_line == 2);
2232 TEST_CONT(tok->source_column == 12);
2233 TEST_CONT(tok->source_len == strlen(buf));
2234 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2235 TEST_CONT(tok->source_line == 2);
2236 TEST_CONT(tok->source_column == 12 + strlen(buf));
2237 TEST_CONT(tok->source_len == 1);
2238 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2239 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2240 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2241 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2242 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2243 tokens = tal_free(tokens);
2246 struct graphql_executable_document *doc;
2247 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2248 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2249 TEST_ABRT(doc != NULL);
2250 TEST_ABRT(doc->first_def != NULL);
2251 TEST_ABRT(doc->first_def->op_def != NULL);
2252 TEST_CONT(doc->first_def->next_def == NULL);
2253 TEST_CONT(doc->first_def->frag_def == NULL);
2254 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2255 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2256 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2257 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2258 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2259 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2260 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2261 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2262 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val != NULL);
2263 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val != NULL);
2264 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val->token_type == 'f');
2265 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val->token_string, buf);
2266 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2267 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2268 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2269 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2270 tokens = tal_free(tokens);
2273 void check_valid_float_values(char *source) {
2274 struct list_head *tokens;
2275 struct graphql_token *tok;
2277 if (!mute) printf("// Valid Float Values\n");
2279 const char *good_values[] = {"1.0", "1e50", "6.0221413e23", "1.23", 0};
2281 for (int i=0; good_values[i]; i++) {
2291 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2292 TEST_ABRT(listlen(tokens) == 11);
2293 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2294 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2295 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2296 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2297 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2298 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'f');
2299 TEST_STRG(tok->token_string, good_values[i]);
2300 TEST_CONT(tok->source_line == 2);
2301 TEST_CONT(tok->source_column == 12);
2302 TEST_CONT(tok->source_len == strlen(good_values[i]));
2303 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2304 TEST_CONT(tok->source_line == 2);
2305 TEST_CONT(tok->source_column == 12 + strlen(good_values[i]));
2306 TEST_CONT(tok->source_len == 1);
2307 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2308 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2309 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2310 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2311 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2312 tokens = tal_free(tokens);
2315 struct graphql_executable_document *doc;
2316 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2317 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2318 TEST_ABRT(doc != NULL);
2319 TEST_ABRT(doc->first_def != NULL);
2320 TEST_ABRT(doc->first_def->op_def != NULL);
2321 TEST_CONT(doc->first_def->next_def == NULL);
2322 TEST_CONT(doc->first_def->frag_def == NULL);
2323 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2324 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2325 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2326 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2327 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2328 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2329 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2330 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2331 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val != NULL);
2332 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val != NULL);
2333 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val->token_type == 'f');
2334 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val->val->token_string, good_values[i]);
2335 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2336 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2337 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2338 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2339 tokens = tal_free(tokens);
2343 void check_invalid_float_values(char *source) {
2344 struct list_head *tokens;
2346 if (!mute) printf("// Invalid Float Values\n");
2348 const char *bad_values[] = {"00.0", "-00.0", "00e1", "1.23.4", "0x1.2p3", 0};
2350 for (int i=0; bad_values[i]; i++) {
2360 TEST_CONT(graphql_lex(NULL, source, &tokens) != NULL);
2361 TEST_ABRT(listlen(tokens) == 5);
2362 tokens = tal_free(tokens);
2364 // No need to test parser when lexer fails.
2368 void check_boolean_values(char *source) {
2369 struct list_head *tokens;
2371 if (!mute) printf("// Boolean Values\n");
2373 const char *good_values[] = {"true", "false", 0};
2375 for (int i=0; good_values[i]; i++) {
2385 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2386 TEST_ABRT(listlen(tokens) == 11);
2387 tokens = tal_free(tokens);
2390 struct graphql_executable_document *doc;
2391 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2392 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2393 TEST_ABRT(doc != NULL);
2394 TEST_ABRT(doc->first_def != NULL);
2395 TEST_ABRT(doc->first_def->op_def != NULL);
2396 TEST_CONT(doc->first_def->next_def == NULL);
2397 TEST_CONT(doc->first_def->frag_def == NULL);
2398 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2399 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2400 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2401 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2402 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2403 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2404 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2405 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2406 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val != NULL);
2407 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val->val != NULL);
2408 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val->val->token_type == 'a');
2409 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val->val->token_string, good_values[i]);
2410 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2411 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2412 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2413 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2414 tokens = tal_free(tokens);
2417 const char *bad_values[] = {"True", "False", "TRUE", "FALSE", 0};
2419 for (int i=0; bad_values[i]; i++) {
2429 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2430 TEST_ABRT(listlen(tokens) == 11);
2431 tokens = tal_free(tokens);
2433 // Test the parser (it will succeed in parsing the bad values as enum values, not boolean values).
2434 struct graphql_executable_document *doc;
2435 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2436 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2437 TEST_ABRT(doc != NULL);
2438 TEST_ABRT(doc->first_def != NULL);
2439 TEST_ABRT(doc->first_def->op_def != NULL);
2440 TEST_CONT(doc->first_def->next_def == NULL);
2441 TEST_CONT(doc->first_def->frag_def == NULL);
2442 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2443 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2444 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2445 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2446 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2447 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2448 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2449 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2450 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->var == NULL);
2451 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val == NULL);
2452 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val == NULL);
2453 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val == NULL);
2454 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val == NULL);
2455 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val == NULL);
2456 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->list_val == NULL);
2457 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val == NULL);
2458 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val != NULL);
2459 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val->val != NULL);
2460 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val->val->token_type == 'a');
2461 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val->val->token_string, bad_values[i]);
2462 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2463 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2464 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2465 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2466 tokens = tal_free(tokens);
2470 void check_string_value(char *source, const char *test_value, const char *expected_result) {
2471 struct list_head *tokens;
2472 struct graphql_token *tok;
2474 if (!mute) printf("// String Value Test: %s\n", test_value);
2484 bool block = (test_value[0]=='\"' && test_value[1]=='\"' && test_value[2]=='\"')? true: false;
2485 if (expected_result) {
2486 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2487 TEST_ABRT(listlen(tokens) == 11);
2488 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2489 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2490 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2491 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2492 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2493 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2494 TEST_STRG(tok->token_string, expected_result);
2495 TEST_CONT(tok->source_line == 2);
2496 TEST_CONT(tok->source_column == 11 + (block? 3: 1));
2497 TEST_CONT(tok->source_len == strlen(test_value) - (block? 6: 2));
2498 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2499 TEST_CONT(tok->source_line == 2);
2500 TEST_CONT(tok->source_column == 11 + strlen(test_value));
2501 TEST_CONT(tok->source_len == 1);
2502 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2503 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2504 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2505 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2506 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2507 tokens = tal_free(tokens);
2509 // Test the parser (it will succeed in parsing the bad values as enum values, not boolean values).
2510 struct graphql_executable_document *doc;
2511 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2512 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2513 TEST_ABRT(doc != NULL);
2514 TEST_ABRT(doc->first_def != NULL);
2515 TEST_ABRT(doc->first_def->op_def != NULL);
2516 TEST_CONT(doc->first_def->next_def == NULL);
2517 TEST_CONT(doc->first_def->frag_def == NULL);
2518 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2519 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2520 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2521 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2522 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2523 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2524 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2525 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2526 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->var == NULL);
2527 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val == NULL);
2528 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val == NULL);
2529 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val == NULL);
2530 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val == NULL);
2531 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val == NULL);
2532 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->list_val == NULL);
2533 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val == NULL);
2534 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val != NULL);
2535 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val->val != NULL);
2536 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val->val->token_type == 's');
2537 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val->val->token_string, expected_result);
2538 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2539 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2540 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next == NULL);
2541 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2542 tokens = tal_free(tokens);
2544 TEST_CONT(graphql_lex(NULL, source, &tokens) != NULL);
2545 tokens = tal_free(tokens);
2549 void check_example_25_and_26(const char *source) {
2550 struct list_head *tokens;
2551 struct graphql_token *tok;
2553 if (!mute) printf("// Example No. 25 and 26\n");
2555 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2556 while ((tok = list_pop(tokens, struct graphql_token, node)) && tok->token_type != 's') { }
2558 TEST_STRG(tok->token_string, "Hello,\n World!\n\nYours,\n GraphQL.");
2561 tokens = tal_free(tokens);
2564 struct graphql_executable_document *doc;
2565 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2566 TEST_CONT(graphql_parse(tokens, &doc) == NULL);
2567 TEST_ABRT(doc != NULL);
2568 tokens = tal_free(tokens);
2571 void check_example_29(char *source) {
2572 struct list_head *tokens;
2573 struct graphql_token *tok;
2575 if (!mute) printf("// Example No. 29\n");
2585 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2586 TEST_ABRT(listlen(tokens) == 9);
2587 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2588 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2589 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2590 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2591 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2592 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2593 TEST_STRG(tok->token_string, "null");
2594 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2595 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2596 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2597 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2598 tokens = tal_free(tokens);
2601 struct graphql_executable_document *doc;
2602 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2603 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
2604 TEST_ABRT(doc != NULL);
2605 TEST_ABRT(doc->first_def != NULL);
2606 TEST_CONT(doc->first_def->next_def == NULL);
2607 TEST_CONT(doc->first_def->frag_def == NULL);
2608 TEST_ABRT(doc->first_def->op_def != NULL);
2609 TEST_CONT(doc->first_def->op_def->op_type == NULL);
2610 TEST_CONT(doc->first_def->op_def->op_name == NULL);
2611 TEST_CONT(doc->first_def->op_def->vars == NULL);
2612 TEST_CONT(doc->first_def->op_def->directives == NULL);
2613 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2614 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2615 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
2616 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
2617 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2618 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
2619 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
2620 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
2621 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "field");
2622 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2623 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2624 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2625 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
2626 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
2627 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "arg");
2628 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2629 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->var == NULL);
2630 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val == NULL);
2631 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val == NULL);
2632 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val == NULL);
2633 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val == NULL);
2634 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->list_val == NULL);
2635 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val == NULL);
2636 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val == NULL);
2637 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val != NULL);
2638 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val->val != NULL);
2639 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val->val->token_type == 'a');
2640 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val->val->token_string, "null");
2641 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
2642 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set == NULL);
2643 TEST_ABRT(doc->first_def->op_def->sel_set->first->next != NULL);
2644 TEST_CONT(doc->first_def->op_def->sel_set->first->next->frag_spread == NULL);
2645 TEST_CONT(doc->first_def->op_def->sel_set->first->next->inline_frag == NULL);
2646 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->field != NULL);
2647 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->alias == NULL);
2648 TEST_ABRT(doc->first_def->op_def->sel_set->first->next->field->name != NULL);
2649 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->name->token_type == 'a');
2650 TEST_STRG(doc->first_def->op_def->sel_set->first->next->field->name->token_string, "field");
2651 TEST_CONT(doc->first_def->op_def->sel_set->first->next->field->args == NULL);
2652 tokens = tal_free(tokens);
2655 void check_example_30_and_31(const char *source) {
2656 struct list_head *tokens;
2657 struct graphql_token *tok;
2659 if (!mute) printf("// Example No. 30 and 31\n");
2661 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2662 TEST_ABRT(listlen(tokens) == 15);
2663 while ((tok = list_pop(tokens, struct graphql_token, node)) && !(tok->token_type == 'a' && tok->token_string != NULL && streq(tok->token_string, "lat"))) { }
2666 TEST_CONT(tok->token_type == 'a');
2667 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2668 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'f');
2669 TEST_STRG(tok->token_string, "-53.211");
2671 tokens = tal_free(tokens);
2673 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2674 while ((tok = list_pop(tokens, struct graphql_token, node)) && !(tok->token_type == 'a' && tok->token_string != NULL && streq(tok->token_string, "lon"))) { }
2677 TEST_CONT(tok->token_type == 'a');
2678 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2679 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'f');
2680 TEST_STRG(tok->token_string, "12.43");
2682 tokens = tal_free(tokens);
2685 struct graphql_executable_document *doc;
2687 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2688 TEST_CONT((e = graphql_parse(tokens, &doc)) == NULL);
2689 if (e) printf("%s\n", e);
2690 TEST_ABRT(doc != NULL);
2691 TEST_ABRT(doc->first_def != NULL);
2692 TEST_CONT(doc->first_def->next_def == NULL);
2693 TEST_CONT(doc->first_def->frag_def == NULL);
2694 TEST_ABRT(doc->first_def->op_def != NULL);
2695 TEST_CONT(doc->first_def->op_def->op_type == NULL);
2696 TEST_CONT(doc->first_def->op_def->op_name == NULL);
2697 TEST_CONT(doc->first_def->op_def->vars == NULL);
2698 TEST_CONT(doc->first_def->op_def->directives == NULL);
2699 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2700 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2701 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2702 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
2703 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
2704 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2705 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
2706 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
2707 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
2708 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "nearestThing");
2709 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
2710 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set == NULL);
2711 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2712 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2713 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2714 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
2715 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
2716 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "location");
2717 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2718 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->var == NULL);
2719 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val == NULL);
2720 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->float_val == NULL);
2721 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->bool_val == NULL);
2722 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->enum_val == NULL);
2723 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->list_val == NULL);
2724 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->null_val == NULL);
2725 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->str_val == NULL);
2726 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val != NULL);
2727 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first != NULL);
2728 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->name != NULL);
2729 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->name->token_type == 'a');
2730 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->val != NULL);
2731 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->val->float_val != NULL);
2732 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->val->float_val->val != NULL);
2733 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->val->float_val->val->token_type == 'f');
2734 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next != NULL);
2735 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->name != NULL);
2736 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->name->token_type == 'a');
2737 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->val != NULL);
2738 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->val->float_val != NULL);
2739 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->val->float_val->val != NULL);
2740 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->val->float_val->val->token_type == 'f');
2741 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->obj_val->first->next->next == NULL);
2742 tokens = tal_free(tokens);
2745 void check_example_32(char *source) {
2746 struct list_head *tokens;
2747 struct graphql_token *tok;
2749 if (!mute) printf("// Example No. 32\n");
2752 query getZuckProfile($devicePicSize: Int) {\n\
2756 profilePic(size: $devicePicSize)\n\
2762 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2763 TEST_ABRT(listlen(tokens) == 27);
2764 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2765 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2766 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2767 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '$');
2768 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2769 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2770 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2771 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2772 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2773 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2774 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2775 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2776 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2777 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'i');
2778 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2779 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2780 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2781 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2782 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2783 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2784 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2785 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2786 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '$');
2787 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2788 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2789 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2790 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2791 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2792 tokens = tal_free(tokens);
2795 struct graphql_executable_document *doc;
2796 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2797 TEST_ABRT(graphql_parse(tokens, &doc) == NULL);
2798 TEST_ABRT(doc != NULL);
2799 TEST_ABRT(doc->first_def != NULL);
2800 TEST_CONT(doc->first_def->next_def == NULL);
2801 TEST_CONT(doc->first_def->frag_def == NULL);
2802 TEST_ABRT(doc->first_def->op_def != NULL);
2803 TEST_ABRT(doc->first_def->op_def->op_type != NULL);
2804 TEST_ABRT(doc->first_def->op_def->op_type->op_type != NULL);
2805 TEST_CONT(doc->first_def->op_def->op_type->op_type->token_type == 'a');
2806 TEST_STRG(doc->first_def->op_def->op_type->op_type->token_string, "query");
2807 TEST_CONT(doc->first_def->op_def->op_name != NULL);
2808 TEST_CONT(doc->first_def->op_def->op_name->token_type == 'a');
2809 TEST_STRG(doc->first_def->op_def->op_name->token_string, "getZuckProfile");
2810 TEST_ABRT(doc->first_def->op_def->vars != NULL);
2811 TEST_ABRT(doc->first_def->op_def->vars->first != NULL);
2812 TEST_CONT(doc->first_def->op_def->vars->first->next == NULL);
2813 TEST_ABRT(doc->first_def->op_def->vars->first->var != NULL);
2814 TEST_ABRT(doc->first_def->op_def->vars->first->var->name != NULL);
2815 TEST_CONT(doc->first_def->op_def->vars->first->var->name->token_type == 'a');
2816 TEST_STRG(doc->first_def->op_def->vars->first->var->name->token_string, "devicePicSize");
2817 TEST_ABRT(doc->first_def->op_def->vars->first->type != NULL);
2818 // TEST_CONT(doc->first_def->op_def->vars->first->type->list == NULL);
2819 // TEST_CONT(doc->first_def->op_def->vars->first->type->non_null == NULL);
2820 TEST_ABRT(doc->first_def->op_def->vars->first->type->named != NULL);
2821 TEST_ABRT(doc->first_def->op_def->vars->first->type->named->name != NULL);
2822 TEST_CONT(doc->first_def->op_def->vars->first->type->named->name->token_type == 'a');
2823 TEST_STRG(doc->first_def->op_def->vars->first->type->named->name->token_string, "Int");
2824 TEST_CONT(doc->first_def->op_def->vars->first->default_val == NULL);
2825 TEST_CONT(doc->first_def->op_def->vars->first->directives == NULL);
2826 TEST_CONT(doc->first_def->op_def->directives == NULL);
2827 TEST_ABRT(doc->first_def->op_def->sel_set != NULL);
2828 TEST_ABRT(doc->first_def->op_def->sel_set->first != NULL);
2829 TEST_CONT(doc->first_def->op_def->sel_set->first->next == NULL);
2830 TEST_CONT(doc->first_def->op_def->sel_set->first->frag_spread == NULL);
2831 TEST_CONT(doc->first_def->op_def->sel_set->first->inline_frag == NULL);
2832 TEST_ABRT(doc->first_def->op_def->sel_set->first->field != NULL);
2833 TEST_CONT(doc->first_def->op_def->sel_set->first->field->alias == NULL);
2834 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->name != NULL);
2835 TEST_CONT(doc->first_def->op_def->sel_set->first->field->name->token_type == 'a');
2836 TEST_STRG(doc->first_def->op_def->sel_set->first->field->name->token_string, "user");
2837 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args != NULL);
2838 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first != NULL);
2839 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->next == NULL);
2840 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->name != NULL);
2841 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->name->token_type == 'a');
2842 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->name->token_string, "id");
2843 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val != NULL);
2844 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val != NULL);
2845 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val != NULL);
2846 TEST_CONT(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_type == 'i');
2847 TEST_STRG(doc->first_def->op_def->sel_set->first->field->args->first->val->int_val->val->token_string, "4");
2848 TEST_CONT(doc->first_def->op_def->sel_set->first->field->directives == NULL);
2849 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set != NULL);
2850 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first != NULL);
2851 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->frag_spread == NULL);
2852 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->inline_frag == NULL);
2853 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field != NULL);
2854 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->alias == NULL);
2855 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name != NULL);
2856 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_type == 'a');
2857 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->name->token_string, "id");
2858 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->args == NULL);
2859 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->directives == NULL);
2860 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->field->sel_set == NULL);
2861 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next != NULL);
2862 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->frag_spread == NULL);
2863 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->inline_frag == NULL);
2864 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field != NULL);
2865 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->alias == NULL);
2866 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name != NULL);
2867 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_type == 'a');
2868 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->name->token_string, "name");
2869 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->args == NULL);
2870 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->directives == NULL);
2871 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->field->sel_set == NULL);
2872 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next != NULL);
2873 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->next == NULL);
2874 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->frag_spread == NULL);
2875 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->inline_frag == NULL);
2876 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field != NULL);
2877 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->alias == NULL);
2878 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name != NULL);
2879 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_type == 'a');
2880 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->name->token_string, "profilePic");
2881 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->directives == NULL);
2882 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->sel_set == NULL);
2883 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args != NULL);
2884 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first != NULL);
2885 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->next == NULL);
2886 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name != NULL);
2887 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_type == 'a');
2888 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->name->token_string, "size");
2889 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val != NULL);
2890 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->var != NULL);
2891 TEST_ABRT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->var->name != NULL);
2892 TEST_CONT(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->var->name->token_type == 'a');
2893 TEST_STRG(doc->first_def->op_def->sel_set->first->field->sel_set->first->next->next->field->args->first->val->var->name->token_string, "devicePicSize");
2894 tokens = tal_free(tokens);
2897 void check_example_34(char *source) {
2898 struct list_head *tokens;
2899 struct graphql_token *tok;
2901 if (!mute) printf("// Example No. 34\n");
2905 @addExternalFields(source: \"profiles\")\n\
2906 @excludeField(name: \"photo\") {\n\
2912 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2913 TEST_ABRT(listlen(tokens) == 21);
2914 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2915 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2916 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '@');
2917 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2918 TEST_STRG(tok->token_string, "addExternalFields");
2919 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2920 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2921 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2922 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2923 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2924 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '@');
2925 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2926 TEST_STRG(tok->token_string, "excludeField");
2927 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2928 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2929 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2930 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2931 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2932 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2933 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2934 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2935 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2936 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2937 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2938 tokens = tal_free(tokens);
2940 // The type system is not yet implemented, so parsing will fail here.
2941 // This could be "phase 2" of this project.
2942 struct graphql_executable_document *doc;
2943 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2944 TEST_CONT(graphql_parse(tokens, &doc) != NULL);
2945 tokens = tal_free(tokens);
2948 void check_example_35(char *source) {
2949 struct list_head *tokens;
2950 struct graphql_token *tok;
2952 if (!mute) printf("// Example No. 35\n");
2956 @excludeField(name: \"photo\")\n\
2957 @addExternalFields(source: \"profiles\") {\n\
2962 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2963 TEST_ABRT(listlen(tokens) == 21);
2964 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2965 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2966 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '@');
2967 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2968 TEST_STRG(tok->token_string, "excludeField");
2969 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2970 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2971 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2972 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2973 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2974 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '@');
2975 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2976 TEST_STRG(tok->token_string, "addExternalFields");
2977 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '(');
2978 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2979 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2980 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 's');
2981 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ')');
2982 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '{');
2983 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2984 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == ':');
2985 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == 'a');
2986 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok->token_type == '}');
2987 tok = list_pop(tokens, struct graphql_token, node); TEST_CONT(tok == NULL);
2988 tokens = tal_free(tokens);
2990 // The type system is not yet implemented, so parsing will fail here.
2991 // This could be "phase 2" of this project.
2992 struct graphql_executable_document *doc;
2993 TEST_CONT(graphql_lex(NULL, source, &tokens) == NULL);
2994 TEST_CONT(graphql_parse(tokens, &doc) != NULL);
2995 tokens = tal_free(tokens);
2998 /* End of test case functions. */
3000 /* Beginning of main() test run to run all test cases. */
3004 printf("\nTesting GraphQL lexer/parser...\n");
3007 int prev_fail; // Used by RUNx macros.
3009 // Check the lexer with all valid line terminators.
3010 const char *new_line = "\n";
3011 const char *carriage_return = "\r";
3012 const char *carriage_return_new_line = "\r\n";
3013 const char *line_terminators[] = { new_line, carriage_return, carriage_return_new_line };
3014 for (int i=0; i<3; i++) {
3021 ", line_terminators[i], line_terminators[i], line_terminators[i], line_terminators[i], line_terminators[i]);
3023 RUN(check_example_3);
3026 RUN(check_example_5); // Parse a mutation operation and check results.
3028 RUN(check_example_6); // Parse an unnamed query and check results.
3030 RUN(check_example_7); // Parse multiple fields in a selection set and check results.
3031 RUN(check_example_8); // Parse complex data structure and check results.
3032 RUN(check_example_9); // Parse example of top-level fields and check results.
3033 RUN(check_example_10); // Parse example with parameterized field and check results.
3034 RUN(check_example_11); // Parse example with multiple field arguments and check results.
3036 // Parse examples of different parameter order and check for identical results.
3039 picture(width: 200, height: 100)\n\
3042 RUN(check_example_12_and_13);
3045 picture(height: 100, width: 200)\n\
3048 RUN(check_example_12_and_13);
3050 RUN(check_example_14); // Parse alias example and check results.
3051 RUN(check_example_16); // Parse a top-level-field alias example and check results.
3053 RUN(check_example_18); // Parse example and check results.
3055 RUN(check_example_19); // Parse fragment example and check results.
3056 RUN(check_example_20); // Parse another fragment example and check results.
3057 RUN(check_example_21); // Parse fragment typing example and check results.
3058 RUN(check_example_23); // Parse fragment typing example and check results.
3059 RUN(check_example_24); // Parse fragment typing example and check results.
3061 // Parse various int values and check results.
3062 for (int i= -15; i<= 15; i++) { RUN1(check_int_value, i); }
3063 for (int i= -32770; i<= -32765; i++) { RUN1(check_int_value, i); }
3064 for (int i= 32765; i<= 32770; i++) { RUN1(check_int_value, i); }
3065 for (int i=-2147483648; i<=-2147483645; i++) { RUN1(check_int_value, i); }
3066 for (int i= 2147483647; i>= 2147483645; i--) { RUN1(check_int_value, i); }
3067 RUN(check_invalid_int_values);
3069 // Parse various float values and check results.
3070 for (float i= -1.0; i<= 1.0; i+= 0.1) { RUN2(check_float_value, i, "%1.1f"); }
3071 for (float i=-327.70; i<=-327.65; i+= 0.01) { RUN2(check_float_value, i, "%1.2f"); }
3072 for (float i= 327.65; i<= 327.70; i+= 0.01) { RUN2(check_float_value, i, "%1.2f"); }
3073 for (float i= -5e-20; i<= -1e-20; i+= 1e-20) { RUN2(check_float_value, i, "%1.0e"); }
3074 for (float i= 5e-20; i>= 1e-20; i-= 1e-20) { RUN2(check_float_value, i, "%1.0e"); }
3075 for (float i= 5E+20; i>= 1E+20; i-= 1E+20) { RUN2(check_float_value, i, "%1.2E"); }
3076 for (float i=1.5E+20; i>=1.1E+20; i-=0.1E+20) { RUN2(check_float_value, i, "%1.1E"); }
3077 RUN(check_valid_float_values);
3078 RUN(check_invalid_float_values);
3080 RUN(check_boolean_values); // Parse boolean values and check results.
3082 // Parse various string values and check results.
3083 RUN2(check_string_value, "te^st", NULL ); // Missing quotes (the caret makes it an invalid token for testing purposes).
3084 RUN2(check_string_value, "\"te^st\"", "te^st" ); // A valid string.
3085 RUN2(check_string_value, "\"\"", "" ); // An empty string is valid.
3086 RUN2(check_string_value, "\"\"\"te^st\"\"\"", "te^st" ); // A block string.
3087 RUN2(check_string_value, "\"te\\st\"", NULL ); // Backslashes are normally invalid.
3088 RUN2(check_string_value, "\"te\nst\"", NULL ); // New-line characters are invalid except in block strings.
3089 RUN2(check_string_value, "\"te\rst\"", NULL ); // New-line characters are invalid except in block strings.
3090 RUN2(check_string_value, "\"\"\"te\nst\"\"\"", "te\nst" ); // New-line characters are valid in block strings.
3091 RUN2(check_string_value, "\"\"\"te\rst\"\"\"", "te\rst" ); // New-line characters are valid in block strings.
3092 RUN2(check_string_value, "\"te\"st\"", NULL ); // A quote in a string is invalid.
3093 RUN2(check_string_value, "\"te\\\"st\"", "te\"st" ); // ...unless it is escaped.
3094 RUN2(check_string_value, "\"\"\"te\"st\"\"\"", "te\"st" ); // A quote in a block string is valid.
3095 RUN2(check_string_value, "\"\"\"te\"\"st\"\"\"", "te\"\"st" ); // It is even valid to have two quotes in a block string.
3096 RUN2(check_string_value, "\"\"\"te\"\"\"st\"\"\"", NULL ); // Three quotes in a row are not allowed in a block string.
3097 RUN2(check_string_value, "\"\"\"te\\\"\"\"st\"\"\"", "te\"\"\"st" ); // ...unless escaped.
3098 RUN2(check_string_value, "\"te\\\"st\"", "te\"st" ); // Check escape sequence.
3099 RUN2(check_string_value, "\"te\\\\st\"", "te\\st" ); // Check escape sequence.
3100 RUN2(check_string_value, "\"te\\/st\"", "te/st" ); // Check escape sequence.
3101 RUN2(check_string_value, "\"te\\bst\"", "te\bst" ); // Check escape sequence.
3102 RUN2(check_string_value, "\"te\\fst\"", "te\fst" ); // Check escape sequence.
3103 RUN2(check_string_value, "\"te\\nst\"", "te\nst" ); // Check escape sequence.
3104 RUN2(check_string_value, "\"te\\rst\"", "te\rst" ); // Check escape sequence.
3105 RUN2(check_string_value, "\"te\\tst\"", "te\tst" ); // Check escape sequence.
3106 RUN2(check_string_value, "\"te\\vst\"", NULL ); // Invalid escape sequence.
3107 RUN2(check_string_value, "\"te\\033st\"", NULL ); // Invalid escape sequence.
3108 // Note: Unicode excape sequence is tested below.
3110 // This block string and this string should result in identical tokens.
3113 sendEmail(message: \"\"\"\n\
3122 RUN(check_example_25_and_26);
3125 sendEmail(message: \"Hello,\\n World!\\n\\nYours,\\n GraphQL.\")\n\
3128 RUN(check_example_25_and_26);
3130 // Check block string example.
3131 RUN2(check_string_value,
3133 This starts with and ends with an empty line,\n\
3134 which makes it easier to read.\n\
3136 "This starts with and ends with an empty line,\nwhich makes it easier to read.");
3138 // Check block string counter example.
3139 RUN2(check_string_value,
3140 "\"\"\"This does not start with or end with any empty lines,\n\
3141 which makes it a little harder to read.\"\"\"",
3142 "This does not start with or end with any empty lines,\nwhich makes it a little harder to read.");
3144 RUN2(check_string_value, "\"te\\u001bst\"", "te\033st" ); // Check unicode escape sequence.
3145 RUN2(check_string_value, "\"te\\u001Bst\"", "te\033st" ); // Check again with other case.
3146 RUN2(check_string_value, "\"\"\"te\\u001bst\"\"\"", "te\\u001bst" ); // Escape sequences are ignored in block strings (except for the triple quote).
3147 RUN2(check_string_value, "\"\"\"te\\nst\"\"\"", "te\\nst" ); // Escape sequences are ignored in block strings (except for the triple quote).
3148 RUN2(check_string_value, "\"te\\u2026st\"", "te\xe2\x80\xa6st"); // Check a unicode escape sequence.
3150 RUN(check_example_29); // Parse null value and check result.
3152 // These two input objects should have the same result.
3155 nearestThing(location: { lon: 12.43, lat: -53.211 })\n\
3158 RUN(check_example_30_and_31);
3161 nearestThing(location: { lat: -53.211, lon: 12.43 })\n\
3164 RUN(check_example_30_and_31);
3166 RUN(check_example_32); // Parse an example with a variable and check result.
3168 RUN(check_example_34); // Parse directives and check result.
3169 RUN(check_example_35); // Parse directives and check result.
3171 RUN(check_example_35); // Parse directives and check result.
3173 printf("total passed: %d\n%stotal failed: %d\033[0m\n", pass, fail?"\033[91m":"", fail);
3175 return fail==0? 0: 1;