MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_string_value

Function check_string_value

ccan/ccan/graphql/test/run.c:2470–2547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2468}
2469
2470void check_string_value(char *source, const char *test_value, const char *expected_result) {
2471 struct list_head *tokens;
2472 struct graphql_token *tok;
2473
2474 if (!mute) printf("// String Value Test: %s\n", test_value);
2475
2476 sprintf(source, "\
2477{\n\
2478 user(id:%s) {\n\
2479 name\n\
2480 }\n\
2481}\n\
2482 ", test_value);
2483
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);
2508
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);

Callers

nothing calls this directly

Calls 4

graphql_lexFunction · 0.85
listlenFunction · 0.85
tal_freeFunction · 0.85
graphql_parseFunction · 0.85

Tested by

no test coverage detected