mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 06:18:07 +03:00
edenfs: fixup PathMap copy and move ctor for case sensitivity
Summary: *shakes fist at C++ copy-constructors* We weren't guaranteeing that case-insensitive status was being propagated on copies or moves, which meant that eg: `lookup("workspace")` would be treated as case-sensitive when mounted case insensitively. Reviewed By: xavierd Differential Revision: D23857218 fbshipit-source-id: 67e33a8455a0a85e5885389b5bb38b20ef043894
This commit is contained in:
parent
65a19aadfe
commit
1c716a1575
@ -120,14 +120,16 @@ class PathMap : private folly::fbvector<std::pair<Key, Value>> {
|
||||
}
|
||||
|
||||
// Inherit the underlying vector copy/assignment.
|
||||
PathMap(const PathMap& other) : Vector(other) {}
|
||||
PathMap(const PathMap& other)
|
||||
: Vector(other), caseSensitive_(other.caseSensitive_) {}
|
||||
PathMap& operator=(const PathMap& other) {
|
||||
PathMap(other).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// inherit Move construction.
|
||||
PathMap(PathMap&& other) noexcept : Vector(std::move(other)) {}
|
||||
PathMap(PathMap&& other) noexcept
|
||||
: Vector(std::move(other)), caseSensitive_(other.caseSensitive_) {}
|
||||
PathMap& operator=(PathMap&& other) {
|
||||
other.swap(*this);
|
||||
return *this;
|
||||
|
@ -32,6 +32,29 @@ TEST(PathMap, caseSensitive) {
|
||||
EXPECT_EQ(map.size(), 3);
|
||||
}
|
||||
|
||||
TEST(PathMap, caseSensitiveCopyMove) {
|
||||
PathMap<bool> map(kPathMapCaseSensitive);
|
||||
map.insert(std::make_pair(PathComponent("foo"), true));
|
||||
|
||||
PathMap<bool> copied(map);
|
||||
EXPECT_TRUE(copied.at("foo"_pc));
|
||||
EXPECT_EQ(copied.find("Foo"_pc), copied.end());
|
||||
|
||||
PathMap<bool> copy_assign(kPathMapCaseInSensitive);
|
||||
copy_assign = map;
|
||||
EXPECT_TRUE(copy_assign.at("foo"_pc));
|
||||
EXPECT_EQ(copy_assign.find("Foo"_pc), copy_assign.end());
|
||||
|
||||
PathMap<bool> moved(std::move(map));
|
||||
EXPECT_TRUE(moved.at("foo"_pc));
|
||||
EXPECT_EQ(moved.find("Foo"_pc), moved.end());
|
||||
|
||||
PathMap<bool> move_assign(kPathMapCaseInSensitive);
|
||||
move_assign = std::move(moved);
|
||||
EXPECT_TRUE(move_assign.at("foo"_pc));
|
||||
EXPECT_EQ(move_assign.find("Foo"_pc), move_assign.end());
|
||||
}
|
||||
|
||||
TEST(PathMap, caseInSensitive) {
|
||||
// Explicitly a case IN-sensitive map, regardless of the host OS
|
||||
PathMap<bool> map(kPathMapCaseInSensitive);
|
||||
@ -60,6 +83,29 @@ TEST(PathMap, caseInSensitive) {
|
||||
EXPECT_EQ(map.begin()->first, "FOO"_pc);
|
||||
}
|
||||
|
||||
TEST(PathMap, caseInSensitiveCopyMove) {
|
||||
PathMap<bool> map(kPathMapCaseInSensitive);
|
||||
map.insert(std::make_pair(PathComponent("foo"), true));
|
||||
|
||||
PathMap<bool> copied(map);
|
||||
EXPECT_TRUE(copied.at("foo"_pc));
|
||||
EXPECT_TRUE(copied.at("Foo"_pc));
|
||||
|
||||
PathMap<bool> copy_assign(kPathMapCaseSensitive);
|
||||
copy_assign = map;
|
||||
EXPECT_TRUE(copy_assign.at("foo"_pc));
|
||||
EXPECT_TRUE(copy_assign.at("Foo"_pc));
|
||||
|
||||
PathMap<bool> moved(std::move(map));
|
||||
EXPECT_TRUE(moved.at("foo"_pc));
|
||||
EXPECT_TRUE(moved.at("Foo"_pc));
|
||||
|
||||
PathMap<bool> move_assign(kPathMapCaseSensitive);
|
||||
move_assign = std::move(moved);
|
||||
EXPECT_TRUE(move_assign.at("foo"_pc));
|
||||
EXPECT_TRUE(move_assign.at("Foo"_pc));
|
||||
}
|
||||
|
||||
TEST(PathMap, insert) {
|
||||
PathMap<bool> map(kPathMapDefaultCaseSensitive);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user