From c556ff98009d06041e2ab99eeb9464233f137725 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 8 May 2024 14:37:17 -0300 Subject: [PATCH] Fix fs_tests with new b8581489f560a6dafceaf7f23ad09509aa24d704 changes --- base/fs_tests.cpp | 97 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/base/fs_tests.cpp b/base/fs_tests.cpp index 8eff88554..3e31aeb88 100644 --- a/base/fs_tests.cpp +++ b/base/fs_tests.cpp @@ -45,96 +45,131 @@ TEST(FS, MakeAllDirectories) TEST(FS, IsPathSeparator) { - EXPECT_TRUE (is_path_separator('\\')); EXPECT_TRUE (is_path_separator('/')); EXPECT_FALSE(is_path_separator('a')); EXPECT_FALSE(is_path_separator('+')); EXPECT_FALSE(is_path_separator(':')); + +#if LAF_WINDOWS + EXPECT_TRUE (is_path_separator('\\')); +#else + EXPECT_FALSE(is_path_separator('\\')); +#endif } TEST(FS, GetFilePath) { - EXPECT_EQ("C:\\foo", get_file_path("C:\\foo\\main.cpp")); EXPECT_EQ("C:/foo", get_file_path("C:/foo/pack.tar.gz")); EXPECT_EQ(".", get_file_path("./main.cpp")); - EXPECT_EQ(".", get_file_path(".\\main.cpp")); EXPECT_EQ("", get_file_path("\\main.cpp")); EXPECT_EQ("", get_file_path("main.cpp")); EXPECT_EQ("", get_file_path("main.")); EXPECT_EQ("", get_file_path("main")); EXPECT_EQ("C:/foo", get_file_path("C:/foo/")); - EXPECT_EQ("C:", get_file_path("C:\\")); - EXPECT_EQ("C:", get_file_path("C:\\.cpp")); EXPECT_EQ("", get_file_path(".cpp")); EXPECT_EQ("", get_file_path("")); + +#if LAF_WINDOWS + EXPECT_EQ("C:\\foo", get_file_path("C:\\foo\\main.cpp")); + EXPECT_EQ(".", get_file_path(".\\main.cpp")); + EXPECT_EQ("C:", get_file_path("C:\\")); + EXPECT_EQ("C:", get_file_path("C:\\.cpp")); +#else + EXPECT_EQ("", get_file_path("C:\\foo\\main.cpp")); + EXPECT_EQ("", get_file_path(".\\main.cpp")); + EXPECT_EQ("", get_file_path("C:\\")); + EXPECT_EQ("", get_file_path("C:\\.cpp")); +#endif } TEST(FS, GetFileName) { - EXPECT_EQ("main.cpp", get_file_name("C:\\foo\\main.cpp")); EXPECT_EQ("pack.tar.gz", get_file_name("C:/foo/pack.tar.gz")); EXPECT_EQ("main.cpp", get_file_name("./main.cpp")); - EXPECT_EQ("main.cpp", get_file_name(".\\main.cpp")); - EXPECT_EQ("main.cpp", get_file_name("\\main.cpp")); EXPECT_EQ("main.cpp", get_file_name("main.cpp")); EXPECT_EQ("main.", get_file_name("main.")); EXPECT_EQ("main", get_file_name("main")); EXPECT_EQ("", get_file_name("C:/foo/")); - EXPECT_EQ("", get_file_name("C:\\")); - EXPECT_EQ(".cpp", get_file_name("C:\\.cpp")); EXPECT_EQ(".cpp", get_file_name(".cpp")); EXPECT_EQ("", get_file_name("")); + +#if LAF_WINDOWS + EXPECT_EQ("main.cpp", get_file_name("C:\\foo\\main.cpp")); + EXPECT_EQ("main.cpp", get_file_name(".\\main.cpp")); + EXPECT_EQ("main.cpp", get_file_name("\\main.cpp")); + EXPECT_EQ("", get_file_name("C:\\")); + EXPECT_EQ(".cpp", get_file_name("C:\\.cpp")); +#else + EXPECT_EQ("C:\\foo\\main.cpp", get_file_name("C:\\foo\\main.cpp")); + EXPECT_EQ(".\\main.cpp", get_file_name(".\\main.cpp")); + EXPECT_EQ("\\main.cpp", get_file_name("\\main.cpp")); + EXPECT_EQ("C:\\", get_file_name("C:\\")); + EXPECT_EQ("C:\\.cpp", get_file_name("C:\\.cpp")); +#endif } TEST(FS, GetFileExtension) { - EXPECT_EQ("cpp", get_file_extension("C:\\foo\\main.cpp")); EXPECT_EQ("gz", get_file_extension("C:/foo/pack.tar.gz")); EXPECT_EQ("cpp", get_file_extension("./main.cpp")); - EXPECT_EQ("cpp", get_file_extension(".\\main.cpp")); - EXPECT_EQ("cpp", get_file_extension("\\main.cpp")); EXPECT_EQ("cpp", get_file_extension("main.cpp")); EXPECT_EQ("", get_file_extension("main.")); EXPECT_EQ("", get_file_extension("main")); EXPECT_EQ("", get_file_extension("C:/foo/")); - EXPECT_EQ("", get_file_extension("C:\\")); - EXPECT_EQ("cpp", get_file_extension("C:\\.cpp")); EXPECT_EQ("cpp", get_file_extension(".cpp")); EXPECT_EQ("", get_file_extension("")); + + // Same results on Windows/macOS/Linux + EXPECT_EQ("cpp", get_file_extension("C:\\foo\\main.cpp")); + EXPECT_EQ("cpp", get_file_extension(".\\main.cpp")); + EXPECT_EQ("cpp", get_file_extension("\\main.cpp")); + EXPECT_EQ("", get_file_extension("C:\\")); + EXPECT_EQ("cpp", get_file_extension("C:\\.cpp")); } TEST(FS, GetFileTitle) { - EXPECT_EQ("main", get_file_title("C:\\foo\\main.cpp")); EXPECT_EQ("pack.tar", get_file_title("C:/foo/pack.tar.gz")); EXPECT_EQ("main", get_file_title("./main.cpp")); - EXPECT_EQ("main", get_file_title(".\\main.cpp")); - EXPECT_EQ("main", get_file_title("\\main.cpp")); EXPECT_EQ("main", get_file_title("main.cpp")); EXPECT_EQ("main", get_file_title("main.")); EXPECT_EQ("main", get_file_title("main")); EXPECT_EQ("", get_file_title("C:/foo/")); - EXPECT_EQ("", get_file_title("C:\\")); - EXPECT_EQ("", get_file_title("C:\\.cpp")); EXPECT_EQ("", get_file_title(".cpp")); EXPECT_EQ("", get_file_title("")); + +#if LAF_WINDOWS + EXPECT_EQ("main", get_file_title("C:\\foo\\main.cpp")); + EXPECT_EQ("main", get_file_title(".\\main.cpp")); + EXPECT_EQ("main", get_file_title("\\main.cpp")); + EXPECT_EQ("", get_file_title("C:\\")); + EXPECT_EQ("", get_file_title("C:\\.cpp")); +#else + EXPECT_EQ("C:\\foo\\main", get_file_title("C:\\foo\\main.cpp")); + EXPECT_EQ(".\\main", get_file_title(".\\main.cpp")); + EXPECT_EQ("\\main", get_file_title("\\main.cpp")); + EXPECT_EQ("C:\\", get_file_title("C:\\")); + EXPECT_EQ("C:\\", get_file_title("C:\\.cpp")); +#endif } TEST(FS, GetFileTitleWithPath) { - EXPECT_EQ("C:\\foo\\main", get_file_title_with_path("C:\\foo\\main.cpp")); EXPECT_EQ("C:/foo/pack.tar", get_file_title_with_path("C:/foo/pack.tar.gz")); EXPECT_EQ("./main", get_file_title_with_path("./main.cpp")); - EXPECT_EQ(".\\main", get_file_title_with_path(".\\main.cpp")); - EXPECT_EQ("\\main", get_file_title_with_path("\\main.cpp")); EXPECT_EQ("main", get_file_title_with_path("main.cpp")); EXPECT_EQ("main", get_file_title_with_path("main.")); EXPECT_EQ("main", get_file_title_with_path("main")); EXPECT_EQ("C:/foo/", get_file_title_with_path("C:/foo/")); - EXPECT_EQ("C:\\", get_file_title_with_path("C:\\")); - EXPECT_EQ("C:\\", get_file_title_with_path("C:\\.cpp")); EXPECT_EQ("", get_file_title_with_path(".cpp")); EXPECT_EQ("", get_file_title_with_path("")); + + // Same results on Windows/macOS/Linux + EXPECT_EQ("C:\\foo\\main", get_file_title_with_path("C:\\foo\\main.cpp")); + EXPECT_EQ(".\\main", get_file_title_with_path(".\\main.cpp")); + EXPECT_EQ("\\main", get_file_title_with_path("\\main.cpp")); + EXPECT_EQ("C:\\", get_file_title_with_path("C:\\")); + EXPECT_EQ("C:\\", get_file_title_with_path("C:\\.cpp")); } TEST(FS, JoinPath) @@ -146,16 +181,26 @@ TEST(FS, JoinPath) EXPECT_EQ("fn", join_path("", "fn")); EXPECT_EQ("/fn", join_path("/", "fn")); EXPECT_EQ("/this"+sep+"fn", join_path("/this", "fn")); + EXPECT_EQ("C:\\path"+sep+"fn", join_path("C:\\path", "fn")); +#if LAF_WINDOWS EXPECT_EQ("C:\\path\\fn", join_path("C:\\path\\", "fn")); +#else + EXPECT_EQ("C:\\path\\/fn", join_path("C:\\path\\", "fn")); +#endif } TEST(FS, RemovePathSeparator) { - EXPECT_EQ("C:\\foo", remove_path_separator("C:\\foo\\")); EXPECT_EQ("C:/foo", remove_path_separator("C:/foo/")); EXPECT_EQ("C:\\foo\\main.cpp", remove_path_separator("C:\\foo\\main.cpp")); EXPECT_EQ("C:\\foo\\main.cpp", remove_path_separator("C:\\foo\\main.cpp/")); + +#if LAF_WINDOWS + EXPECT_EQ("C:\\foo", remove_path_separator("C:\\foo\\")); +#else + EXPECT_EQ("C:\\foo\\", remove_path_separator("C:\\foo\\")); +#endif } TEST(FS, HasFileExtension)