1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// okay to copy/adapt

int _test_parse_string_length_1() {
    mu_start();
    //────────────────────
    char* result;
    char const* input = "\"A\"";
    char const* pos = input;
    bool is_success = parse_string(&result, &pos);
    mu_check(is_success);
    mu_check_strings_equal(result, "A");
    mu_check(pos == input + 3);
    free(result);
    //────────────────────
    mu_end();
}

int _test_parse_string_invalid_no_starting_quote() {
    mu_start();
    //────────────────────
    char* result;
    char const* input = "A"; // invalid because A is not a "
    char const* pos = input;
    bool is_success = parse_string(&result, &pos);
    mu_check(!is_success);
    mu_check(pos == input);
    //────────────────────
    mu_end();
}

int _test_parse_element_integer_element() {
    mu_start();
    //────────────────────
    Element element;
    char const* input = "123";
    char const* pos = input;
    bool is_success = parse_element(&element, &pos);
    mu_check(is_success);
    mu_check(pos == input + 3);
    mu_check(element.type == ELEMENT_INT);
    mu_check(element.as_int == 123);
    free_element(&element);
    //────────────────────
    mu_end();
}

int _test_parse_element_string_element() {
    mu_start();
    //────────────────────
    Element element;
    char const* input = "\"ABC\"trailing characters";
    char const* pos = input;
    bool is_success = parse_element(&element, &pos);
    mu_check(is_success);
    mu_check(pos == input + 5);
    mu_check(element.type == ELEMENT_STRING);
    mu_check_strings_equal(element.as_string, "ABC");
    free_element(&element);
    //────────────────────
    mu_end();
}

int main(int argc, char* argv[]) {
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2024 Alexander J. Quinn & David Burnett         This content is protected and may not be shared, uploaded, or distributed.