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
72
73
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>


int _test_linked_list_on_stack_example() {
    mu_start();
    //────────────────────
    // probably don't want to copy/adapt this example
    // this is valid, but a little awkward
    Node second_node = { .next = NULL, .string = "Hello" };
    Node head = { .next = &second_node, .string = "Hello" };
    Strings needles = {
        .head = &head,
        .tail = &second_node,
        .num_strings = 0
    };

    // other code


    // do not call free_strings in this example, all nodes
    // are stack allocated and strings are data segment strings
    //free_strings(&needles);
    //────────────────────
    mu_end();
}

// okay to copy/adapt
// helper to not always need to call strlen
void _append_needle(char const* string, Strings* a_strings) {
    append_substring(string, strlen(string), a_strings);
}

int _test_split_string_two_delimiters_one_match() {
    mu_start();
    //────────────────────
    Strings needles = {
        .head = NULL,
        .tail = NULL,
        .num_strings = 0
    };
    _append_needle("+", &needles);
    _append_needle("-", &needles);
    char const* input = "Hello+World";
    Strings result = splti_string(input, needles);

    // list size checks
    mu_check(result.num_strings == 3);
    mu_check(result.head != NULL);
    mu_check(result.head->next != NULL);
    mu_check(result.head->next->next != NULL);
    mu_check(result.head->next->next->next == NULL);
    mu_check(result.tail == result.head->next->next);

    // string checks
    mu_check_strings_equal("Hello", result.head->string);
    mu_check_strings_equal("World", result.head->next->next->string);
    // delimiter checks
    mu_check_strings_equal("+", result.head->next->string);

    free_strings(&needles);
    free_strings(&result);
    //────────────────────
    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.