Lolly 1.4.27
Loading...
Searching...
No Matches
Functions
string_u16_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "lolly/data/string_u16.hpp"
#include <doctest/doctest.h>
Include dependency graph for string_u16_test.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("equality of string")
 
 TEST_CASE ("compare string")
 
 TEST_CASE ("test slice")
 
 TEST_CASE ("test concat")
 
 TEST_CASE ("test append")
 
 TEST_CASE ("test reserve along with append")
 
 TEST_CASE ("test expand_or_shrink_by along with sub index")
 
 TEST_CASE ("test resize")
 
 TEST_CASE ("test copy")
 
 TEST_CASE ("test iteration")
 

Function Documentation

◆ TEST_CASE() [1/10]

TEST_CASE ( "equality of string" )

Definition at line 14 of file string_u16_test.cpp.

14 {
15 CHECK_EQ (string_u16 () == string_u16 (), true);
16
17 CHECK_EQ (string_u16 (u"abc") == u"abc", true);
18 CHECK_EQ (u"abc" == string_u16 (u"abc"), true);
19
20 CHECK_EQ (string_u16 (u"abc") == u"", false);
21 CHECK_EQ (u"" == string_u16 (u"abc"), false);
22
23 CHECK_EQ (string_u16 (u"abc") != u"abc", false);
24 CHECK_EQ (u"abc" != string_u16 (u"abc"), false);
25
26 CHECK_EQ (string_u16 (u"abc") != u"", true);
27 CHECK_EQ (u"" != string_u16 (u"abc"), true);
28
29 CHECK_EQ (string_u16 (u"abc") == string_u16 (u"abc"), true);
30 CHECK_EQ (string_u16 (u"abc") == string_u16 (), false);
31 CHECK_EQ (string_u16 (u"abc") != string_u16 (u"abc"), false);
32 CHECK_EQ (string_u16 (u"abc") != string_u16 (), true);
33}
The list class represents a linked list.
Definition list.hpp:48

◆ TEST_CASE() [2/10]

TEST_CASE ( "compare string" )

Definition at line 35 of file string_u16_test.cpp.

35 {
36 CHECK (string_u16 (u"ab") < string_u16 (u"b"));
37 CHECK (!(string_u16 (u"b") < string_u16 (u"ab")));
38 CHECK (string_u16 () < string_u16 (u"0"));
39 CHECK (!(string_u16 (u"0") < string_u16 ()));
40 CHECK (string_u16 (u"a") <= string_u16 (u"a"));
41 CHECK (!(string_u16 (u"ab") <= string_u16 (u"a")));
42 CHECK (string_u16 (u"ab") <= string_u16 (u"b"));
43 CHECK (!(string_u16 (u"b") <= string_u16 (u"ab")));
44 CHECK (string_u16 () <= string_u16 ());
45 CHECK (string_u16 () <= string_u16 (u"0"));
46 CHECK (!(string_u16 (u"0") <= string_u16 ()));
47}

◆ TEST_CASE() [3/10]

TEST_CASE ( "test slice" )

Definition at line 49 of file string_u16_test.cpp.

49 {
50 auto abcde= string_u16 (u"abcde");
51 CHECK_EQ (abcde (0, 0) == string_u16 (), true);
52 CHECK_EQ (abcde (0, 1) == string_u16 (u"a"), true);
53 CHECK_EQ (abcde (1, 3) (0, 1) == string_u16 (u"b"), true);
54 CHECK_EQ (abcde (0, 10) == string_u16 (u"abcde"), true);
55 CHECK_EQ (abcde (-1, 1) == string_u16 (u"a"), true);
56 CHECK_EQ (abcde (3, 2) == string_u16 (), true);
57 CHECK_EQ (abcde (3, -2) == string_u16 (), true);
58 CHECK_EQ (abcde (10, 11) == string_u16 (), true);
59 CHECK_EQ (abcde (-3, -2) == string_u16 (), true);
60
61 // string_view == string
62 CHECK_EQ (string_u16 (u"a") == abcde (0, 1), true);
63}

◆ TEST_CASE() [4/10]

TEST_CASE ( "test concat" )

Definition at line 65 of file string_u16_test.cpp.

65 {
66 CHECK_EQ (string_u16 (u"abc") * u"de" == string_u16 (u"abcde"), true);
67 CHECK_EQ (string_u16 (u"abc") * string_u16 (u"de") == string_u16 (u"abcde"),
68 true);
69 CHECK_EQ (string_u16 (u"abc") * string_u16 (u"Hello") (0, 2) ==
70 string_u16 (u"abcHe"),
71 true);
72}

◆ TEST_CASE() [5/10]

TEST_CASE ( "test append" )

Definition at line 78 of file string_u16_test.cpp.

78 {
79 auto str= string_u16 ();
80 str << u'x';
81 CHECK (str == u"x");
82 str << string_u16 (u"yz");
83 CHECK (str == u"xyz");
84}

◆ TEST_CASE() [6/10]

TEST_CASE ( "test reserve along with append" )

Definition at line 86 of file string_u16_test.cpp.

86 {
87
88 SUBCASE ("reserved more space") {
89 auto str= string_u16 ();
90 str->reserve (6);
91 str << u'x';
92 CHECK_EQ (str == u"x", true);
93 str << string_u16 (u"yz");
94 CHECK_EQ (str == u"xyz", true);
95 str << string_u16 (u": larger than reserved space");
96 CHECK_EQ (str == u"xyz: larger than reserved space", true);
97 }
98 SUBCASE ("reserved the same space") {
99 auto str= string_u16 (u"abc");
100 str->reserve (3);
101 CHECK_EQ (str == u"abc", true);
102 }
103 SUBCASE ("reserved less space should take no effect") {
104 auto str= string_u16 (u"abc");
105 str->reserve (2);
106 CHECK_EQ (str == u"abc", true);
107 }
108}

◆ TEST_CASE() [7/10]

TEST_CASE ( "test expand_or_shrink_by along with sub index" )

Definition at line 110 of file string_u16_test.cpp.

110 {
111
112 SUBCASE ("expand") {
113 auto str = string_u16 (u"abc");
114 int previous_n= str->expand_or_shrink_by (1);
115 CHECK_EQ (previous_n, 3);
116 str[3]= u'd';
117 CHECK_EQ (str == u"abcd", true);
118 }
119 SUBCASE ("shrink") {
120 auto str = string_u16 (u"abc");
121 int previous_n= str->expand_or_shrink_by (-1);
122 CHECK_EQ (previous_n, 3);
123 CHECK_EQ (str == u"ab", true);
124 }
125 SUBCASE ("delta 0 takes no effect") {
126 auto str = string_u16 (u"abc");
127 int previous_n= str->expand_or_shrink_by (0);
128 CHECK_EQ (previous_n, 3);
129 CHECK_EQ (str == u"abc", true);
130 }
131}

◆ TEST_CASE() [8/10]

TEST_CASE ( "test resize" )

Definition at line 133 of file string_u16_test.cpp.

133 {
134
135 SUBCASE ("expand") {
136 auto str= string_u16 (u"abc");
137 str->resize (4);
138 str[3]= u'd';
139 CHECK_EQ (str == u"abcd", true);
140 }
141 SUBCASE ("shrink") {
142 auto str= string_u16 (u"abc");
143 str->resize (2);
144 CHECK_EQ (str == u"ab", true);
145 }
146 SUBCASE ("delta 0 takes no effect") {
147 auto str= string_u16 (u"abc");
148 str->resize (3);
149 CHECK_EQ (str == u"abc", true);
150 }
151}

◆ TEST_CASE() [9/10]

TEST_CASE ( "test copy" )

Definition at line 153 of file string_u16_test.cpp.

153 {
154 string_u16 str1= u"str1";
156 CHECK (str1 == str2);
157 CHECK (str1.buffer () != str2.buffer ());
158
159 string_u16 str3= copy (str1 (0, 3));
160 CHECK (str3 == u"str");
161}
lolly_tree< T > copy(lolly_tree< T > t)

◆ TEST_CASE() [10/10]

TEST_CASE ( "test iteration" )

Definition at line 163 of file string_u16_test.cpp.

163 {
164 string_u16 str1 = u"s\0tr1";
165 int expectedIndex= 0;
166 for (const auto element : str1) {
169 }
171}
int N(lolly_tree< T > t)