| Flutter macOS Embedder |

text_range_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/common/text_range.h"
6
7 #include "gtest/gtest.h"
8
9 namespace flutter {
10
11 TEST(TextRange, TextRangeFromPositionZero) {
12 TextRange range(0);
13 EXPECT_EQ(range.base(), size_t(0));
14 EXPECT_EQ(range.extent(), size_t(0));
15 EXPECT_EQ(range.start(), size_t(0));
16 EXPECT_EQ(range.end(), size_t(0));
17 EXPECT_EQ(range.length(), size_t(0));
18 EXPECT_EQ(range.position(), size_t(0));
19 EXPECT_TRUE(range.collapsed());
20 }
21
22 TEST(TextRange, TextRangeFromPositionNonZero) {
23 TextRange range(3);
24 EXPECT_EQ(range.base(), size_t(3));
25 EXPECT_EQ(range.extent(), size_t(3));
26 EXPECT_EQ(range.start(), size_t(3));
27 EXPECT_EQ(range.end(), size_t(3));
28 EXPECT_EQ(range.length(), size_t(0));
29 EXPECT_EQ(range.position(), size_t(3));
30 EXPECT_TRUE(range.collapsed());
31 }
32
33 TEST(TextRange, TextRangeFromRange) {
34 TextRange range(3, 7);
35 EXPECT_EQ(range.base(), size_t(3));
36 EXPECT_EQ(range.extent(), size_t(7));
37 EXPECT_EQ(range.start(), size_t(3));
38 EXPECT_EQ(range.end(), size_t(7));
39 EXPECT_EQ(range.length(), size_t(4));
40 EXPECT_FALSE(range.collapsed());
41 }
42
43 TEST(TextRange, TextRangeFromReversedRange) {
44 TextRange range(7, 3);
45 EXPECT_EQ(range.base(), size_t(7));
46 EXPECT_EQ(range.extent(), size_t(3));
47 EXPECT_EQ(range.start(), size_t(3));
48 EXPECT_EQ(range.end(), size_t(7));
49 EXPECT_EQ(range.length(), size_t(4));
50 EXPECT_FALSE(range.collapsed());
51 }
52
53 TEST(TextRange, SetBase) {
54 TextRange range(3, 7);
55 range.set_base(4);
56 EXPECT_EQ(range.base(), size_t(4));
57 EXPECT_EQ(range.extent(), size_t(7));
58 }
59
60 TEST(TextRange, SetBaseReversed) {
61 TextRange range(7, 3);
62 range.set_base(5);
63 EXPECT_EQ(range.base(), size_t(5));
64 EXPECT_EQ(range.extent(), size_t(3));
65 }
66
67 TEST(TextRange, SetExtent) {
68 TextRange range(3, 7);
69 range.set_extent(6);
70 EXPECT_EQ(range.base(), size_t(3));
71 EXPECT_EQ(range.extent(), size_t(6));
72 }
73
74 TEST(TextRange, SetExtentReversed) {
75 TextRange range(7, 3);
76 range.set_extent(4);
77 EXPECT_EQ(range.base(), size_t(7));
78 EXPECT_EQ(range.extent(), size_t(4));
79 }
80
81 TEST(TextRange, SetStart) {
82 TextRange range(3, 7);
83 range.set_start(5);
84 EXPECT_EQ(range.base(), size_t(5));
85 EXPECT_EQ(range.extent(), size_t(7));
86 }
87
88 TEST(TextRange, SetStartReversed) {
89 TextRange range(7, 3);
90 range.set_start(5);
91 EXPECT_EQ(range.base(), size_t(7));
92 EXPECT_EQ(range.extent(), size_t(5));
93 }
94
95 TEST(TextRange, SetEnd) {
96 TextRange range(3, 7);
97 range.set_end(6);
98 EXPECT_EQ(range.base(), size_t(3));
99 EXPECT_EQ(range.extent(), size_t(6));
100 }
101
102 TEST(TextRange, SetEndReversed) {
103 TextRange range(7, 3);
104 range.set_end(5);
105 EXPECT_EQ(range.base(), size_t(5));
106 EXPECT_EQ(range.extent(), size_t(3));
107 }
108
109 TEST(TextRange, ContainsPreStartPosition) {
110 TextRange range(2, 6);
111 EXPECT_FALSE(range.Contains(1));
112 }
113
114 TEST(TextRange, ContainsStartPosition) {
115 TextRange range(2, 6);
116 EXPECT_TRUE(range.Contains(2));
117 }
118
119 TEST(TextRange, ContainsMiddlePosition) {
120 TextRange range(2, 6);
121 EXPECT_TRUE(range.Contains(3));
122 EXPECT_TRUE(range.Contains(4));
123 }
124
125 TEST(TextRange, ContainsEndPosition) {
126 TextRange range(2, 6);
127 EXPECT_TRUE(range.Contains(6));
128 }
129
130 TEST(TextRange, ContainsPostEndPosition) {
131 TextRange range(2, 6);
132 EXPECT_FALSE(range.Contains(7));
133 }
134
135 TEST(TextRange, ContainsPreStartPositionReversed) {
136 TextRange range(6, 2);
137 EXPECT_FALSE(range.Contains(1));
138 }
139
140 TEST(TextRange, ContainsStartPositionReversed) {
141 TextRange range(6, 2);
142 EXPECT_TRUE(range.Contains(2));
143 }
144
145 TEST(TextRange, ContainsMiddlePositionReversed) {
146 TextRange range(6, 2);
147 EXPECT_TRUE(range.Contains(3));
148 EXPECT_TRUE(range.Contains(4));
149 }
150
151 TEST(TextRange, ContainsEndPositionReversed) {
152 TextRange range(6, 2);
153 EXPECT_TRUE(range.Contains(6));
154 }
155
156 TEST(TextRange, ContainsPostEndPositionReversed) {
157 TextRange range(6, 2);
158 EXPECT_FALSE(range.Contains(7));
159 }
160
161 TEST(TextRange, ContainsRangePreStartPosition) {
162 TextRange range(2, 6);
163 EXPECT_FALSE(range.Contains(TextRange(0, 1)));
164 }
165
166 TEST(TextRange, ContainsRangeSpanningStartPosition) {
167 TextRange range(2, 6);
168 EXPECT_FALSE(range.Contains(TextRange(1, 3)));
169 }
170
171 TEST(TextRange, ContainsRangeStartPosition) {
172 TextRange range(2, 6);
173 EXPECT_TRUE(range.Contains(TextRange(2)));
174 }
175
176 TEST(TextRange, ContainsRangeMiddlePosition) {
177 TextRange range(2, 6);
178 EXPECT_TRUE(range.Contains(TextRange(3, 4)));
179 EXPECT_TRUE(range.Contains(TextRange(4, 5)));
180 }
181
182 TEST(TextRange, ContainsRangeEndPosition) {
183 TextRange range(2, 6);
184 EXPECT_TRUE(range.Contains(TextRange(6)));
185 }
186
187 TEST(TextRange, ContainsRangeSpanningEndPosition) {
188 TextRange range(2, 6);
189 EXPECT_FALSE(range.Contains(TextRange(5, 7)));
190 }
191
192 TEST(TextRange, ContainsRangePostEndPosition) {
193 TextRange range(2, 6);
194 EXPECT_FALSE(range.Contains(TextRange(6, 7)));
195 }
196
197 TEST(TextRange, ContainsRangePreStartPositionReversed) {
198 TextRange range(6, 2);
199 EXPECT_FALSE(range.Contains(TextRange(0, 1)));
200 }
201
202 TEST(TextRange, ContainsRangeSpanningStartPositionReversed) {
203 TextRange range(6, 2);
204 EXPECT_FALSE(range.Contains(TextRange(1, 3)));
205 }
206
207 TEST(TextRange, ContainsRangeStartPositionReversed) {
208 TextRange range(6, 2);
209 EXPECT_TRUE(range.Contains(TextRange(2)));
210 }
211
212 TEST(TextRange, ContainsRangeMiddlePositionReversed) {
213 TextRange range(6, 2);
214 EXPECT_TRUE(range.Contains(TextRange(3, 4)));
215 EXPECT_TRUE(range.Contains(TextRange(4, 5)));
216 }
217
218 TEST(TextRange, ContainsRangeSpanningEndPositionReversed) {
219 TextRange range(6, 2);
220 EXPECT_FALSE(range.Contains(TextRange(5, 7)));
221 }
222
223 TEST(TextRange, ContainsRangeEndPositionReversed) {
224 TextRange range(6, 2);
225 EXPECT_TRUE(range.Contains(TextRange(5)));
226 }
227
228 TEST(TextRange, ContainsRangePostEndPositionReversed) {
229 TextRange range(6, 2);
230 EXPECT_FALSE(range.Contains(TextRange(6, 7)));
231 }
232
233 TEST(TextRange, ReversedForwardRange) {
234 TextRange range(2, 6);
235 EXPECT_FALSE(range.reversed());
236 }
237
238 TEST(TextRange, ReversedCollapsedRange) {
239 TextRange range(2, 2);
240 EXPECT_FALSE(range.reversed());
241 }
242
243 TEST(TextRange, ReversedReversedRange) {
244 TextRange range(6, 2);
245 EXPECT_TRUE(range.reversed());
246 }
247
248 } // namespace flutter
flutter::TextRange
Definition: text_range.h:19
flutter::TextRange::set_end
void set_end(size_t pos)
Definition: text_range.h:57
flutter::TextRange::reversed
bool reversed() const
Definition: text_range.h:80
flutter::TextRange::position
size_t position() const
Definition: text_range.h:68
flutter::TextRange::set_extent
void set_extent(size_t pos)
Definition: text_range.h:39
flutter::TextRange::set_base
void set_base(size_t pos)
Definition: text_range.h:33
flutter::TextRange::Contains
bool Contains(size_t position) const
Definition: text_range.h:83
flutter::TextRange::start
size_t start() const
Definition: text_range.h:42
flutter::TextRange::base
size_t base() const
Definition: text_range.h:30
flutter::TextRange::collapsed
bool collapsed() const
Definition: text_range.h:77
flutter::TextRange::length
size_t length() const
Definition: text_range.h:74
flutter::TextRange::extent
size_t extent() const
Definition: text_range.h:36
flutter::TextRange::set_start
void set_start(size_t pos)
Definition: text_range.h:45
flutter::TextRange::end
size_t end() const
Definition: text_range.h:54
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::TEST
TEST(BasicMessageChannelTest, Registration)
Definition: basic_message_channel_unittests.cc:58
text_range.h