Mercurial > irccd
diff tests/util/main.cpp @ 514:16b9ebfd3f08
Irccd: get rid of fs.hpp, closes #594
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 24 Oct 2017 12:52:20 +0200 |
parents | 7e273b7f4f92 |
children | b557017ad3f0 |
line wrap: on
line diff
--- a/tests/util/main.cpp Mon Oct 23 21:30:17 2017 +0200 +++ b/tests/util/main.cpp Tue Oct 24 12:52:20 2017 +0200 @@ -271,7 +271,7 @@ std::string result = util::strip(value); BOOST_REQUIRE_EQUAL("", result); -} +} BOOST_AUTO_TEST_SUITE_END() @@ -460,4 +460,58 @@ BOOST_AUTO_TEST_SUITE_END() +/* + * util::fs::find function (name) + * ------------------------------------------------------------------ + */ + +BOOST_AUTO_TEST_SUITE(fs_find_name) + +BOOST_AUTO_TEST_CASE(not_recursive) +{ + auto file1 = util::fs::find(CMAKE_CURRENT_BINARY_DIR "/root", "file-1.txt", false); + auto file2 = util::fs::find(CMAKE_CURRENT_BINARY_DIR "/root", "file-2.txt", false); + + BOOST_TEST(file1.find("file-1.txt") != std::string::npos); + BOOST_TEST(file2.empty()); +} + +BOOST_AUTO_TEST_CASE(recursive) +{ + auto file1 = util::fs::find(CMAKE_CURRENT_BINARY_DIR "/root", "file-1.txt", true); + auto file2 = util::fs::find(CMAKE_CURRENT_BINARY_DIR "/root", "file-2.txt", true); + + BOOST_TEST(file1.find("file-1.txt") != std::string::npos); + BOOST_TEST(file2.find("file-2.txt") != std::string::npos); +} + +BOOST_AUTO_TEST_SUITE_END() + +/* + * util::fs::find function (regex) + * ------------------------------------------------------------------ + */ + +BOOST_AUTO_TEST_SUITE(fs_find_regex) + +BOOST_AUTO_TEST_CASE(not_recursive) +{ + const std::regex regex("file-[12]\\.txt"); + + auto file = util::fs::find(TESTS_BINARY_DIR "/root", regex, false); + + BOOST_TEST(file.find("file-1.txt") != std::string::npos); +} + +BOOST_AUTO_TEST_CASE(recursive) +{ + const std::regex regex("file-[12]\\.txt"); + + auto file = util::fs::find(TESTS_BINARY_DIR "/root/level-a", regex, true); + + BOOST_TEST(file.find("file-2.txt") != std::string::npos); +} + +BOOST_AUTO_TEST_SUITE_END() + } // !irccd