From a793f7b2894c8655106606dfa00001975409b04a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 17 Aug 2017 22:58:50 +0100 Subject: [PATCH] moar tests --- test/unit/test_make_filerecord_tree.cpp | 23 +++++++-- test/unit/test_pathname.cpp | 65 ++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/test/unit/test_make_filerecord_tree.cpp b/test/unit/test_make_filerecord_tree.cpp index 5e1bb10..0655a89 100644 --- a/test/unit/test_make_filerecord_tree.cpp +++ b/test/unit/test_make_filerecord_tree.cpp @@ -57,7 +57,24 @@ TEST(machinery, make_filerecord_tree) { }; std::vector 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& 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()); } diff --git a/test/unit/test_pathname.cpp b/test/unit/test_pathname.cpp index 5724cc3..a647526 100644 --- a/test/unit/test_pathname.cpp +++ b/test/unit/test_pathname.cpp @@ -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)); }