mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
moar tests
This commit is contained in:
parent
7f50f264e5
commit
a793f7b289
2 changed files with 84 additions and 4 deletions
|
@ -57,7 +57,24 @@ TEST(machinery, make_filerecord_tree) {
|
|||
};
|
||||
std::vector<FileRecordNode> results = make_filerecord_tree(records);
|
||||
|
||||
for (const auto& result : results) {
|
||||
std::cout << result.index << ' ' << records[result.index].path() << '\n';
|
||||
}
|
||||
//for (const auto& result : results) {
|
||||
// std::cout << result.index << ' ' << records[result.index].path() << '\n';
|
||||
//}
|
||||
|
||||
ASSERT_EQ(6, results.size());
|
||||
EXPECT_EQ("gtest", records[results[0].index].path());
|
||||
EXPECT_EQ("unit", records[results[1].index].path());
|
||||
EXPECT_EQ("unit_cli/CMakeFiles", records[results[2].index].path());
|
||||
EXPECT_EQ("unit_cli/CTestTestfile.cmake", records[results[3].index].path());
|
||||
EXPECT_EQ("unit_cli/Makefile", records[results[4].index].path());
|
||||
EXPECT_EQ("unit_cli/cmake_install.cmake", records[results[5].index].path());
|
||||
|
||||
const std::vector<FileRecordNode>& gtest = results[0].children;
|
||||
ASSERT_EQ(6, gtest.size());
|
||||
EXPECT_EQ("gtest/CMakeFiles/CMakeDirectoryInformation.cmake", records[gtest[0].index].path());
|
||||
EXPECT_EQ("gtest/CMakeFiles/gtest.dir", records[gtest[1].index].path());
|
||||
EXPECT_EQ("gtest/CMakeFiles/gtest_main.dir/depend.internal", records[gtest[2].index].path());
|
||||
EXPECT_EQ("gtest/CMakeFiles/gtest_main.dir/link.txt", records[gtest[3].index].path());
|
||||
EXPECT_EQ("gtest/CMakeFiles/gtest_main.dir/src", records[gtest[4].index].path());
|
||||
EXPECT_EQ("gtest/CMakeFiles/progress.marks", records[gtest[5].index].path());
|
||||
}
|
||||
|
|
|
@ -66,12 +66,75 @@ TEST(machinery, pathname) {
|
|||
EXPECT_EQ(2, attachments.atom_count());
|
||||
EXPECT_EQ("attachments/important", attachments.path());
|
||||
}
|
||||
|
||||
{
|
||||
PathName test("/////home/duckz/////many////slashes///////////////");
|
||||
EXPECT_EQ(4, test.atom_count());
|
||||
EXPECT_TRUE(test.is_absolute());
|
||||
EXPECT_EQ("/home/duckz/many/slashes", test.path());
|
||||
|
||||
test.join("..");
|
||||
EXPECT_EQ(5, test.atom_count());
|
||||
EXPECT_EQ("/home/duckz/many/slashes/..", test.path());
|
||||
|
||||
test.pop_right();
|
||||
EXPECT_EQ(4, test.atom_count());
|
||||
EXPECT_EQ("/home/duckz/many/slashes", test.path());
|
||||
test.pop_right();
|
||||
EXPECT_EQ(3, test.atom_count());
|
||||
EXPECT_EQ("/home/duckz/many", test.path());
|
||||
test.pop_right();
|
||||
EXPECT_EQ(2, test.atom_count());
|
||||
EXPECT_EQ("/home/duckz", test.path());
|
||||
test.pop_right();
|
||||
EXPECT_EQ(1, test.atom_count());
|
||||
EXPECT_EQ("/home", test.path());
|
||||
test.pop_right();
|
||||
EXPECT_EQ(0, test.atom_count());
|
||||
EXPECT_EQ("/", test.path());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(machinery, pathname_functions) {
|
||||
using mchlib::PathName;
|
||||
using mchlib::make_relative_path;
|
||||
//using mchlib::make_relative_path;
|
||||
using mchlib::basename;
|
||||
using mchlib::is_ancestor;
|
||||
using mchlib::are_siblings;
|
||||
|
||||
PathName home("/home/duckz/");
|
||||
PathName jpeg("pic.jpg");
|
||||
PathName bpg("pic2.pbg");
|
||||
PathName pics_rel("pictures/wallpapers");
|
||||
PathName full_jpeg_path(home);
|
||||
full_jpeg_path.join(pics_rel);
|
||||
full_jpeg_path.join(jpeg);
|
||||
PathName full_bpg_path(home);
|
||||
full_bpg_path.join(pics_rel);
|
||||
full_bpg_path.join(bpg);
|
||||
PathName pics_abs(home);
|
||||
pics_abs.join(pics_rel);
|
||||
|
||||
EXPECT_EQ(2, home.atom_count());
|
||||
EXPECT_EQ(1, jpeg.atom_count());
|
||||
EXPECT_EQ(2, pics_rel.atom_count());
|
||||
EXPECT_EQ(4, pics_abs.atom_count());
|
||||
|
||||
EXPECT_EQ("/home/duckz/pictures/wallpapers", pics_abs.path());
|
||||
EXPECT_EQ("/home/duckz/pictures/wallpapers/pic.jpg", full_jpeg_path.path());
|
||||
|
||||
EXPECT_EQ("pic.jpg", basename(full_jpeg_path));
|
||||
EXPECT_EQ("pic.jpg", basename(jpeg));
|
||||
EXPECT_EQ("wallpapers", basename(pics_abs));
|
||||
EXPECT_EQ("wallpapers", basename(pics_rel));
|
||||
|
||||
EXPECT_FALSE(are_siblings(home, pics_rel));
|
||||
EXPECT_FALSE(are_siblings(home, pics_abs));
|
||||
EXPECT_TRUE(are_siblings(full_bpg_path, full_jpeg_path));
|
||||
EXPECT_TRUE(are_siblings(bpg, jpeg));
|
||||
|
||||
EXPECT_TRUE(is_ancestor(home, pics_abs, 0));
|
||||
EXPECT_FALSE(is_ancestor(home, pics_abs, 1));
|
||||
EXPECT_TRUE(is_ancestor(home, pics_abs, 2));
|
||||
EXPECT_TRUE(is_ancestor(home, pics_abs, 3));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue