DisplayBuffer: check_invariant method to assert atoms consistency

This commit is contained in:
Maxime Coste 2011-09-29 09:10:27 +00:00
parent e659ea2dab
commit 834e2d2fe3
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,6 @@
#include "display_buffer.hh" #include "display_buffer.hh"
#include "assert.h" #include "assert.hh"
namespace Kakoune namespace Kakoune
{ {
@ -22,4 +22,14 @@ DisplayBuffer::iterator DisplayBuffer::split(iterator atom, size_t pos_in_atom)
return insert(atom, std::move(new_atom)); return insert(atom, std::move(new_atom));
} }
void DisplayBuffer::check_invariant() const
{
for (size_t i = 0; i < m_atoms.size(); ++i)
{
assert(m_atoms[i].end > m_atoms[i].begin);
if (i > 0)
assert(m_atoms[i-1].end == m_atoms[i].begin);
}
}
} }

View File

@ -75,6 +75,8 @@ public:
const_iterator begin() const { return m_atoms.begin(); } const_iterator begin() const { return m_atoms.begin(); }
const_iterator end() const { return m_atoms.end(); } const_iterator end() const { return m_atoms.end(); }
void check_invariant() const;
private: private:
AtomList m_atoms; AtomList m_atoms;
}; };

View File

@ -309,7 +309,10 @@ void Window::update_display_buffer()
m_display_buffer.append(DisplayAtom(begin, end, m_buffer.string(begin, end))); m_display_buffer.append(DisplayAtom(begin, end, m_buffer.string(begin, end)));
for (auto& filter : m_filters) for (auto& filter : m_filters)
{
filter(m_display_buffer); filter(m_display_buffer);
m_display_buffer.check_invariant();
}
} }
void Window::set_dimensions(const WindowCoord& dimensions) void Window::set_dimensions(const WindowCoord& dimensions)