Skip to content

Commit

Permalink
Fix fs_tests with new b858148 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed May 8, 2024
1 parent b858148 commit c556ff9
Showing 1 changed file with 71 additions and 26 deletions.
97 changes: 71 additions & 26 deletions base/fs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c556ff9

Please sign in to comment.