mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-31 23:28:45 +00:00
Add some tests for dirname and basename
This is in preparation for replacing our wrappers around the C versions, with custom versions instead.
This commit is contained in:
parent
a7c37e4af4
commit
6e1b324343
1 changed files with 37 additions and 0 deletions
|
@ -6217,6 +6217,42 @@ void test_normalize_path() {
|
|||
do_test(path_normalize_for_cd(L"/abc/def/", L"../ghi/..") == L"/abc/ghi/..");
|
||||
}
|
||||
|
||||
void test_dirname_basename() {
|
||||
say(L"Testing wdirname and wbasename");
|
||||
const struct testcase_t {
|
||||
const wchar_t *path;
|
||||
const wchar_t *dir;
|
||||
const wchar_t *base;
|
||||
} testcases[] = {
|
||||
{L"", L".", L"."},
|
||||
{L"foo//", L".", L"foo"},
|
||||
{L"foo//////", L".", L"foo"},
|
||||
{L"/////foo", L"/", L"foo"},
|
||||
{L"/////foo", L"/", L"foo"},
|
||||
{L"//foo/////bar", L"//foo", L"bar"},
|
||||
{L"foo/////bar", L"foo", L"bar"},
|
||||
|
||||
// Examples given in XPG4.2.
|
||||
{L"/usr/lib", L"/usr", L"lib"},
|
||||
{L"usr", L".", L"usr"},
|
||||
{L"/", L"/", L"/"},
|
||||
{L".", L".", L"."},
|
||||
{L"..", L".", L".."},
|
||||
};
|
||||
for (const auto &tc : testcases) {
|
||||
wcstring dir = wdirname(tc.path);
|
||||
if (dir != tc.dir) {
|
||||
err(L"Wrong dirname for \"%ls\": expected \"%ls\", got \"%ls\"", tc.path, tc.dir,
|
||||
dir.c_str());
|
||||
}
|
||||
wcstring base = wbasename(tc.path);
|
||||
if (base != tc.base) {
|
||||
err(L"Wrong basename for \"%ls\": expected \"%ls\", got \"%ls\"", tc.path, tc.base,
|
||||
base.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_topic_monitor() {
|
||||
say(L"Testing topic monitor");
|
||||
topic_monitor_t monitor;
|
||||
|
@ -6562,6 +6598,7 @@ int main(int argc, char **argv) {
|
|||
if (should_test_function("layout_cache")) test_layout_cache();
|
||||
if (should_test_function("prompt")) test_prompt_truncation();
|
||||
if (should_test_function("normalize")) test_normalize_path();
|
||||
if (should_test_function("dirname")) test_dirname_basename();
|
||||
if (should_test_function("topics")) test_topic_monitor();
|
||||
if (should_test_function("topics")) test_topic_monitor_torture();
|
||||
if (should_test_function("pipes")) test_pipes();
|
||||
|
|
Loading…
Reference in a new issue