2012-03-21 20:27:36 +01:00
|
|
|
#include "buffer.hh"
|
|
|
|
#include "assert.hh"
|
2012-04-01 17:39:53 +02:00
|
|
|
#include "editor.hh"
|
|
|
|
#include "selectors.hh"
|
2012-03-21 20:27:36 +01:00
|
|
|
|
|
|
|
using namespace Kakoune;
|
|
|
|
|
2012-04-01 17:39:53 +02:00
|
|
|
void test_buffer()
|
2012-03-21 20:27:36 +01:00
|
|
|
{
|
|
|
|
Buffer buffer("test", Buffer::Type::Scratch, "allo ?\nmais que fais la police\n hein ?\n youpi\n");
|
|
|
|
assert(buffer.line_count() == 4);
|
|
|
|
|
|
|
|
BufferIterator i = buffer.begin();
|
|
|
|
assert(*i == 'a');
|
|
|
|
i += 6;
|
|
|
|
assert(buffer.line_and_column_at(i) == BufferCoord{0 COMMA 6});
|
|
|
|
i += 1;
|
|
|
|
assert(buffer.line_and_column_at(i) == BufferCoord{1 COMMA 0});
|
|
|
|
--i;
|
|
|
|
assert(buffer.line_and_column_at(i) == BufferCoord{0 COMMA 6});
|
|
|
|
++i;
|
|
|
|
assert(buffer.line_and_column_at(i) == BufferCoord{1 COMMA 0});
|
|
|
|
buffer.modify(Modification::make_insert(i, "tchou kanaky\n"));
|
|
|
|
assert(buffer.line_count() == 5);
|
|
|
|
|
|
|
|
BufferIterator begin = buffer.iterator_at({ 4, 1 });
|
|
|
|
BufferIterator end = buffer.iterator_at({ 4, 5 }) + 1;
|
|
|
|
String str = buffer.string(begin, end);
|
|
|
|
assert(str == "youpi");
|
|
|
|
}
|
|
|
|
|
2012-04-01 17:39:53 +02:00
|
|
|
void test_editor()
|
|
|
|
{
|
|
|
|
Buffer buffer("test", Buffer::Type::Scratch, "test\n\nyoupi\n");
|
|
|
|
Editor editor(buffer);
|
|
|
|
|
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
editor.select(select_whole_buffer);
|
|
|
|
editor.multi_select(std::bind(select_all_matches, _1, "\n\\h*"));
|
|
|
|
for (auto& sel : editor.selections())
|
|
|
|
{
|
|
|
|
assert(*sel.begin() == '\n');
|
|
|
|
editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:27:36 +01:00
|
|
|
void run_unit_tests()
|
|
|
|
{
|
|
|
|
test_buffer();
|
2012-04-01 17:39:53 +02:00
|
|
|
test_editor();
|
2012-03-21 20:27:36 +01:00
|
|
|
}
|