~kiwec/ke

ref: 2133c126a17a4627ffb76143c19c287e9c272749 ke/test/Document.cc -rw-r--r-- 1.1 KiB
2133c126 — Wolf Clément Add error, info and success messages 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "Document.hpp"

void test_inserted_text() {
  Text text;
  std::wstring inserted_text = L"abcd\nefg";
  text.insert(inserted_text.c_str(), inserted_text.size(), text.size());

  // Strings are the same
  TEST_CHECK(text.size() == inserted_text.size());
  for(uint i = 0; i < text.size(); i++) {
    TEST_CHECK(text[i] == inserted_text[i]);
  }
}

void test_data_erasing() {
  Data<char> text;
  auto inserted_text = "abcdefg\n1234";
  text.insert(inserted_text, strlen(inserted_text), text.size());
  text.erase(0, 1);

  // Test contents
  auto wanted_text = "bcdefg\n1234";
  for(uint i = 0; i < text.size(); i++) {
    TEST_CHECK(wanted_text[i] == text[i]);
  }
}

void test_text_erasing() {
  Text text;
  auto inserted_text = L"abcdef";
  text.insert(inserted_text, wcslen(inserted_text), text.size());

  // Test size
  text.erase(1, 1);
  auto wanted_len = wcslen(inserted_text) - 1;
  TEST_CHECK(text.size() == wanted_len);

  // Test contents, '\0' included
  auto wanted_text = L"acdef";
  for(uint i = 0; i < text.size() + 1; i++) {
    TEST_CHECK(wanted_text[i] == text[i]);
  }
}