mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-16 11:35:49 +00:00
Fix unit test
This commit is contained in:
parent
c4a68356f6
commit
6362f0f002
3 changed files with 19 additions and 49 deletions
|
@ -50,21 +50,9 @@ namespace mchlib {
|
|||
reference dereference ( void ) const;
|
||||
bool is_end ( void ) const;
|
||||
|
||||
//There are three iterators and an offset because the first item
|
||||
//could very well be detached from the rest of its siblings. For
|
||||
//example "a", "b", "a/c", "a/d": when iterating on that sequence the
|
||||
//expected outcome is "a", "a/c", "a/d". So in order to be able to
|
||||
//iterate back and forward we need a "first" iterator so we can
|
||||
//always get back to it whene we are decrementing an iterator to
|
||||
//"a/c" for example. current is just the current iterator, and the
|
||||
//offset is needed so we can tell if at any moment we are at
|
||||
//first+offset and skip back to first instead of decrementing
|
||||
//current. end is just there so we know when to stop advancing.
|
||||
VecIterator m_first;
|
||||
VecIterator m_current;
|
||||
VecIterator m_end;
|
||||
std::unique_ptr<PathName> m_base_path;
|
||||
std::vector<FileRecordData>::difference_type m_second_offs;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -45,62 +45,42 @@ namespace mchlib {
|
|||
|
||||
namespace implem {
|
||||
DirIterator::DirIterator (DirIterator&& parOther) :
|
||||
m_first(std::move(parOther.m_first)),
|
||||
m_current(std::move(parOther.m_current)),
|
||||
m_end(std::move(parOther.m_end)),
|
||||
m_base_path(std::move(parOther.m_base_path)),
|
||||
m_second_offs(parOther.m_second_offs)
|
||||
m_base_path(std::move(parOther.m_base_path))
|
||||
{
|
||||
}
|
||||
|
||||
DirIterator::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath) :
|
||||
m_first(parBegin),
|
||||
m_current(parBegin),
|
||||
m_end(parEnd),
|
||||
m_base_path(std::move(parBasePath)),
|
||||
m_second_offs(0)
|
||||
m_base_path(std::move(parBasePath))
|
||||
{
|
||||
assert(m_current == m_end or m_base_path->atom_count() == m_current->level);
|
||||
|
||||
//Look for the point where the children of this entry starts
|
||||
auto search_second = parBegin;
|
||||
while (
|
||||
search_second != m_end and (
|
||||
search_second->level == m_base_path->atom_count() or
|
||||
*m_base_path != PathName(search_second->abs_path).pop_right()
|
||||
m_current != m_end and (
|
||||
m_current->level == m_base_path->atom_count() or
|
||||
*m_base_path != PathName(m_current->abs_path).pop_right()
|
||||
)) {
|
||||
assert(search_second->level == m_base_path->atom_count());
|
||||
++search_second;
|
||||
//assert(m_current->level == m_base_path->atom_count());
|
||||
++m_current;
|
||||
}
|
||||
m_second_offs = std::distance(parBegin, search_second);
|
||||
}
|
||||
|
||||
DirIterator::~DirIterator() noexcept {
|
||||
}
|
||||
|
||||
void DirIterator::increment() {
|
||||
if (m_current == m_first and m_second_offs > 1) {
|
||||
m_current = m_first + m_second_offs;
|
||||
}
|
||||
else {
|
||||
++m_current;
|
||||
}
|
||||
++m_current;
|
||||
}
|
||||
|
||||
void DirIterator::decrement() {
|
||||
if (m_current == m_first + m_second_offs) {
|
||||
m_current = m_first;
|
||||
}
|
||||
else {
|
||||
--m_current;
|
||||
}
|
||||
--m_current;
|
||||
}
|
||||
|
||||
void DirIterator::advance (std::size_t parAdvance) {
|
||||
if (m_current == m_first and parAdvance > 0) {
|
||||
--parAdvance;
|
||||
m_current = m_first + m_second_offs;
|
||||
}
|
||||
m_current += parAdvance;
|
||||
}
|
||||
|
||||
|
|
|
@ -912,15 +912,17 @@ TEST(machinery, diriterator) {
|
|||
SetListing lst(std::move(test_data));
|
||||
|
||||
auto i = lst.begin();
|
||||
EXPECT_EQ("", i->abs_path);
|
||||
|
||||
++i;
|
||||
EXPECT_EQ("BestAndBest", i->abs_path);
|
||||
|
||||
auto view = SetListingView(i);
|
||||
auto i2 = view.cbegin();
|
||||
EXPECT_EQ("BestAndBest/CD1", i2->abs_path);
|
||||
{
|
||||
auto view = SetListingView(i);
|
||||
auto i2 = view.cbegin();
|
||||
EXPECT_EQ("BestAndBest/CD1", i2->abs_path);
|
||||
|
||||
++i2;
|
||||
EXPECT_EQ("BestAndBest/CD2", i2->abs_path);
|
||||
++i2;
|
||||
EXPECT_EQ("BestAndBest/CD2", i2->abs_path);
|
||||
}
|
||||
|
||||
++i;
|
||||
EXPECT_EQ("City Hunter", i->abs_path);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue