diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-20 18:07:43 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-20 18:07:43 +0200 |
commit | 9f7bf8ddf255f06a3c27c13dad87e34a70356d58 (patch) | |
tree | a09f18cbf96bd8f983ad1b67de22d57561ce4cf1 /02_exercise/prompt_utils_test.c | |
parent | 08d6167988a0bbec72d84ff12f8857f0b4d0b42a (diff) | |
download | betriebssysteme-9f7bf8ddf255f06a3c27c13dad87e34a70356d58.tar.gz betriebssysteme-9f7bf8ddf255f06a3c27c13dad87e34a70356d58.zip |
First implementation of prompt
Diffstat (limited to '02_exercise/prompt_utils_test.c')
-rw-r--r-- | 02_exercise/prompt_utils_test.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/02_exercise/prompt_utils_test.c b/02_exercise/prompt_utils_test.c new file mode 100644 index 0000000..b26ce6f --- /dev/null +++ b/02_exercise/prompt_utils_test.c @@ -0,0 +1,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"); +}
\ No newline at end of file |