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

// okay to copy/adapt

int _test_split_string_one_delimiter_occurs_twice() {
    mu_start();
    //────────────────────
    char const* text = "ABC-DEF-GHI";
    char* strings[] = { "-" };
    struct Strings delimiters = {
        .num_strings = 1,
        .strings = strings
    }
    struct Strings result = split_string(text, delimiters);
    mu_check(result.num_strings == 5);
    mu_check_strings_equal(result.strings[0], "ABC");
    mu_check_strings_equal(result.strings[1], "-");
    mu_check_strings_equal(result.strings[2], "DEF");
    mu_check_strings_equal(result.strings[3], "-");
    mu_check_strings_equal(result.strings[4], "GHI");

    free_strings(&result);
    // DON'T free delimiters, I stack/data allocated it 
    //────────────────────
    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.