From 31ed1339325be8572cd74f08d379e4421332360b Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 21 Oct 2019 13:42:25 +0300 Subject: [PATCH] Added dir_name tests --- tests/test_create_dir.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index 5e1a2659..3849e2fe 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -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 + }