add more asserts

This commit is contained in:
Maxime Coste 2013-01-23 14:25:48 +01:00
parent f14bc5e310
commit 3404366b65
4 changed files with 14 additions and 5 deletions

View File

@ -245,7 +245,8 @@ void Buffer::check_invariant() const
void Buffer::do_insert(const BufferIterator& pos, const String& content) void Buffer::do_insert(const BufferIterator& pos, const String& content)
{ {
assert(pos.is_end() or utf8::is_character_start(pos)); assert(pos.is_valid() and (pos.is_end() or utf8::is_character_start(pos)));
assert(not contains(content, '\0'));
++m_timestamp; ++m_timestamp;
ByteCount offset = pos.offset(); ByteCount offset = pos.offset();
@ -322,6 +323,8 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content)
void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end) void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
{ {
assert(begin.is_valid());
assert(end.is_valid());
assert(utf8::is_character_start(begin) and assert(utf8::is_character_start(begin) and
(end.is_end() or utf8::is_character_start(end))); (end.is_end() or utf8::is_character_start(end)));
++m_timestamp; ++m_timestamp;

View File

@ -64,7 +64,10 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections)
void DynamicSelectionList::check_invariant() const void DynamicSelectionList::check_invariant() const
{ {
for (auto& sel : *this) for (auto& sel : *this)
{
assert(m_buffer == &sel.buffer()); assert(m_buffer == &sel.buffer());
sel.check_invariant();
}
} }
void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end) void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIterator& end)
@ -73,7 +76,6 @@ void DynamicSelectionList::on_insert(const BufferIterator& begin, const BufferIt
{ {
sel.first().on_insert(begin.coord(), end.coord()); sel.first().on_insert(begin.coord(), end.coord());
sel.last().on_insert(begin.coord(), end.coord()); sel.last().on_insert(begin.coord(), end.coord());
sel.check_invariant();
} }
} }
@ -83,7 +85,6 @@ void DynamicSelectionList::on_erase(const BufferIterator& begin, const BufferIte
{ {
sel.first().on_erase(begin.coord(), end.coord()); sel.first().on_erase(begin.coord(), end.coord());
sel.last().on_erase(begin.coord(), end.coord()); sel.last().on_erase(begin.coord(), end.coord());
sel.check_invariant();
} }
} }

View File

@ -334,12 +334,15 @@ public:
void on_insert(const BufferIterator& begin, const BufferIterator& end) void on_insert(const BufferIterator& begin, const BufferIterator& end)
{ {
assert(begin.is_valid());
assert(end.is_valid());
m_first = begin; m_first = begin;
m_last = utf8::previous(end); m_last = utf8::previous(end);
} }
void on_erase(const BufferIterator& begin, const BufferIterator& end) void on_erase(const BufferIterator& begin, const BufferIterator& end)
{ {
assert(begin.is_valid());
m_first = begin; m_first = begin;
if (m_first >= m_buffer.end()) if (m_first >= m_buffer.end())
m_first = utf8::previous(m_buffer.end()); m_first = utf8::previous(m_buffer.end());

View File

@ -26,8 +26,10 @@ BufferIterator Range::end() const
void Range::check_invariant() const void Range::check_invariant() const
{ {
assert(utf8::is_character_start(first())); assert(m_first.is_valid());
assert(utf8::is_character_start(last())); assert(m_last.is_valid());
assert(utf8::is_character_start(m_first));
assert(utf8::is_character_start(m_last));
} }
static void avoid_eol(BufferIterator& it) static void avoid_eol(BufferIterator& it)