Added dir_name tests

This commit is contained in:
gabime 2019-10-21 13:42:25 +03:00
parent 9a68bd8cc8
commit 31ed133932

View File

@ -23,5 +23,36 @@ TEST_CASE("create_dir", "[create_dir]")
test_create_dir("./test_logs/dir1/dir3", "test_logs/dir1/dir3");
test_create_dir("test_logs/../test_logs/dir1/dir4", "test_logs/dir1/dir4");
test_create_dir("./test_logs/dir1/dir2/dir99/../dir23", "test_logs/dir1/dir2/dir23");
spdlog::drop("test-create-dir");
}
TEST_CASE("dir_name", "[create_dir]")
{
using spdlog::details::os::dir_name;
REQUIRE(dir_name("").empty());
REQUIRE(dir_name("dir").empty());
REQUIRE(dir_name("dir/") == "dir");
REQUIRE(dir_name("dir///") == "dir//");
REQUIRE(dir_name("dir/file") == "dir");
REQUIRE(dir_name("dir/file.txt") == "dir");
REQUIRE(dir_name("dir/file.txt/") == "dir/file.txt");
REQUIRE(dir_name("/dir/file.txt") == "/dir");
REQUIRE(dir_name("//dir/file.txt") == "//dir");
REQUIRE(dir_name("//dir/file.txt") == "//dir");
REQUIRE(dir_name("../file.txt") == "..");
REQUIRE(dir_name("./file.txt") == ".");
#ifdef WIN32
REQUIRE(dir_name(R"(dir\)") == "dir");
REQUIRE(dir_name(R"(dir\\\)") == "dir//");
REQUIRE(dir_name(R"(dir\file)") == "dir");
REQUIRE(dir_name(R"(dir\file.txt)") == "dir");
REQUIRE(dir_name(R"(dir\file.txt\)") == "dir/file.txt");
REQUIRE(dir_name(R"(\dir\file.txt)") == "/dir");
REQUIRE(dir_name(R"(\\dir\file.txt)") == "//dir");
REQUIRE(dir_name(R"(\\dir\file.txt)") == "//dir");
REQUIRE(dir_name(R"(..\file.txt)") == "..");
REQUIRE(dir_name(R"(.\file.txt)") == ".");
REQUIRE(dir_name(R"(c:\\a\b\c\d\file.txt)") == "c://a/b/c/d");
//REQUIRE(dir_name(R"(c:\\a)") == "c://");
#endif
}