#ifndef SK_TEST_PATH_H #define SK_TEST_PATH_H #include #include static void test_is_relative(bool oracle, char const* text) { struct path path; path_init(&path, text); CU_ASSERT_FATAL(path_is_relative(&path) == oracle); path_free(&path); } static void test_path_relative() { test_is_relative(true, "./module.sk"); test_is_relative(false, "module.sk"); test_is_relative(false, "/home/module.sk"); test_is_relative(false, ""); } static void test_path_set_ext(char const* oracle, char const* text, char const* ext) { struct path path; path_init(&path, text); path_set_ext(&path, ext); if (strcmp(path.str->value, oracle) != 0) { fprintf(stderr, "\n%s + %s", text, ext); fprintf(stderr, "\n%s <> %s\n", oracle, path.str->value); } CU_ASSERT_STRING_EQUAL_FATAL(path.str->value, oracle); path_free(&path); } static void test_path_ext() { test_path_set_ext("./hello/world", "./hello/world", ""); test_path_set_ext("./hello/world", "./hello/world.sk", ""); test_path_set_ext("./hello/world.sk", "./hello/world", "sk"); test_path_set_ext("./hello/world.sk", "./hello/world.sk", "sk"); test_path_set_ext("./hello/world.sk", "./hello/world.com", "sk"); } static void test_path_extract_name(char const* text, char const* oracle) { struct path path; path_init(&path, text); struct str s; str_init(&s); path_extract_name(&path, &s); if (strcmp(s.value, oracle) != 0) { fprintf(stderr, "\n%s <> %s\n", oracle, s.value); } CU_ASSERT_STRING_EQUAL_FATAL(s.value, oracle); str_free(&s); path_free(&path); } static void test_path_extract() { test_path_extract_name("world.sk", "world.sk"); test_path_extract_name("./world.sk", "world.sk"); test_path_extract_name("./../world.sk", "../world.sk"); test_path_extract_name("./world", "world"); test_path_extract_name("./hello/world", "hello/world"); } void register_path() { CU_pSuite suite = CU_add_suite("Path", 0, 0); CU_add_test(suite, "Relative paths", test_path_relative); CU_add_test(suite, "Extensions", test_path_ext); CU_add_test(suite, "Extract name", test_path_extract); } #endif