Skip to content

Commit

Permalink
test: add tests for dir_entry_view::parent()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 23, 2024
1 parent 8c8e646 commit 11f6405
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/compat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,33 @@ void check_compat(logger& lgr, reader::filesystem_v2 const& fs,
}
EXPECT_EQ(expected, paths) << td;
}

{
auto dev = fs.find("foo/1/2/3/4/5/6/7/8/9/j");
ASSERT_TRUE(dev);
EXPECT_EQ("j", dev->name());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_regular_file());
dev = dev->parent();
EXPECT_EQ("9", dev->name());
EXPECT_EQ("foo/1/2/3/4/5/6/7/8/9", dev->unix_path());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
dev = dev->parent()->parent()->parent();
EXPECT_EQ("6", dev->name());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
dev = dev->parent()->parent()->parent()->parent()->parent()->parent();
EXPECT_EQ("foo", dev->name());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
dev = dev->parent();
ASSERT_TRUE(dev);
EXPECT_EQ("", dev->name());
EXPECT_TRUE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
EXPECT_FALSE(dev->parent());
}
}

} // namespace
Expand Down
19 changes: 19 additions & 0 deletions test/dwarfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,25 @@ void basic_end_to_end_test(
ASSERT_TRUE(info.count("root"));
}
}

{
auto dev = fs.find("somedir/ipsum.py");
ASSERT_TRUE(dev);
EXPECT_EQ("ipsum.py", dev->name());
EXPECT_EQ("somedir/ipsum.py", dev->unix_path());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_regular_file());
dev = dev->parent();
EXPECT_EQ("somedir", dev->name());
EXPECT_FALSE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
dev = dev->parent();
ASSERT_TRUE(dev);
EXPECT_EQ("", dev->name());
EXPECT_TRUE(dev->is_root());
EXPECT_TRUE(dev->inode().is_directory());
EXPECT_FALSE(dev->parent());
}
}

std::vector<std::string> const compressions{
Expand Down

0 comments on commit 11f6405

Please sign in to comment.