summaryrefslogtreecommitdiff
path: root/src/unit_tests.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-03-21 19:27:36 +0000
committerMaxime Coste <frrrwww@gmail.com>2012-03-21 19:27:36 +0000
commita555e28b4e69a01e191589acf4bc040885c33676 (patch)
tree815a240ba5df666b68d061d7c9c1bb5ad5c9c030 /src/unit_tests.cc
parent0748aa042b5497ba8e219ecc5ec2f9610b2fed74 (diff)
add basic unit tests run at startup
Diffstat (limited to 'src/unit_tests.cc')
-rw-r--r--src/unit_tests.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/unit_tests.cc b/src/unit_tests.cc
new file mode 100644
index 00000000..3cb7598c
--- /dev/null
+++ b/src/unit_tests.cc
@@ -0,0 +1,33 @@
+#include "buffer.hh"
+#include "assert.hh"
+
+using namespace Kakoune;
+
+int test_buffer()
+{
+ 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");
+}
+
+void run_unit_tests()
+{
+ test_buffer();
+}