summaryrefslogtreecommitdiffstats
path: root/02_exercise/prompt_utils_test.c
blob: b26ce6f6e20e0c84af829f7679e6019d65b51dd0 (plain) (blame)
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 "array.h"
#include "prompt_utils.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>

void test_get_seperator_indeces() {
    char const *const test_str = "/This/is/a/test";
    size_t const *const result = get_seperator_indeces(test_str, '/');
    for (size_t i = 0; i < arrayLen(result); i++) {
        printf("%ld : %s \n", result[i], test_str + result[i]);
    }
}
void test_paths(char const *const from, char const *const to,
                char const *const expected) {
    size_t const *const result = get_seperator_indeces(from, '/');
    for (size_t i = 0; i < arrayLen(result); i++) {
        printf("%ld : %s \n", result[i], from + result[i]);
    }
    size_t const *const result2 = get_seperator_indeces(to, '/');
    for (size_t i = 0; i < arrayLen(result2); i++) {
        printf("%ld : %s \n", result2[i], to + result2[i]);
    }
    char const *const path = relative_path(from, to);
    printf("The relative path of %s to %s is %s \n", from, to, path);

    assert(strcmp(path, expected) == 0);
}
void test_relative_path() {
    test_paths("/Test", "/Test/a", "./a");
    test_paths("/abc/def/ghi", "/abc/def/ghi", ".");
    test_paths("/Test", "/Test/a/asd", "./a/asd");
    test_paths("/Test/b/c", "/Test/b", "..");
    test_paths("/", "/Test/a/asd", "./Test/a/asd");
    test_paths("/Test/c", "/Test/b", "../b");
}