add == and != comparisons for Tree objects

Summary:
Add == and != operators for Tree and TreeEntry.
These are mainly useful for unit tests to compare that imported trees look as
expected.

Reviewed By: wez

Differential Revision: D5365956

fbshipit-source-id: c039dfc58e430e99466db1a6c891a3c50d7906fe
This commit is contained in:
Adam Simpkins 2017-07-05 11:17:03 -07:00 committed by Facebook Github Bot
parent 1f52adbca4
commit 7e7d208127
4 changed files with 39 additions and 0 deletions

23
eden/fs/model/Tree.cpp Normal file
View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "Tree.h"
namespace facebook {
namespace eden {
bool operator==(const Tree& tree1, const Tree& tree2) {
return (tree1.getHash() == tree2.getHash()) &&
(tree1.getTreeEntries() == tree2.getTreeEntries());
}
bool operator!=(const Tree& tree1, const Tree& tree2) {
return !(tree1 == tree2);
}
}
}

View File

@ -61,5 +61,8 @@ class Tree {
const Hash hash_;
const std::vector<TreeEntry> entries_;
};
bool operator==(const Tree& tree1, const Tree& tree2);
bool operator!=(const Tree& tree1, const Tree& tree2);
}
}

View File

@ -27,5 +27,16 @@ std::ostream& operator<<(std::ostream& os, TreeEntryType type) {
os << "TreeEntryType::" << int(type);
return os;
}
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2) {
return (entry1.getHash() == entry2.getHash()) &&
(entry1.getFileType() == entry2.getFileType()) &&
(entry1.getOwnerPermissions() == entry2.getOwnerPermissions()) &&
(entry1.getName() == entry2.getName());
}
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2) {
return !(entry1 == entry2);
}
}
}

View File

@ -98,5 +98,7 @@ class TreeEntry {
};
std::ostream& operator<<(std::ostream& os, TreeEntryType type);
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2);
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2);
}
}