Flutter Engine
The Flutter Engine
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
9namespace flutter {
10
11TEST(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
22TEST(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
33TEST(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
43TEST(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
53TEST(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
60TEST(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
67TEST(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
74TEST(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
81TEST(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
88TEST(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
95TEST(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
102TEST(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
109TEST(TextRange, ContainsPreStartPosition) {
110 TextRange range(2, 6);
111 EXPECT_FALSE(range.Contains(1));
112}
113
114TEST(TextRange, ContainsStartPosition) {
115 TextRange range(2, 6);
116 EXPECT_TRUE(range.Contains(2));
117}
118
119TEST(TextRange, ContainsMiddlePosition) {
120 TextRange range(2, 6);
121 EXPECT_TRUE(range.Contains(3));
122 EXPECT_TRUE(range.Contains(4));
123}
124
125TEST(TextRange, ContainsEndPosition) {
126 TextRange range(2, 6);
127 EXPECT_TRUE(range.Contains(6));
128}
129
130TEST(TextRange, ContainsPostEndPosition) {
131 TextRange range(2, 6);
132 EXPECT_FALSE(range.Contains(7));
133}
134
135TEST(TextRange, ContainsPreStartPositionReversed) {
136 TextRange range(6, 2);
137 EXPECT_FALSE(range.Contains(1));
138}
139
140TEST(TextRange, ContainsStartPositionReversed) {
141 TextRange range(6, 2);
142 EXPECT_TRUE(range.Contains(2));
143}
144
145TEST(TextRange, ContainsMiddlePositionReversed) {
146 TextRange range(6, 2);
147 EXPECT_TRUE(range.Contains(3));
148 EXPECT_TRUE(range.Contains(4));
149}
150
151TEST(TextRange, ContainsEndPositionReversed) {
152 TextRange range(6, 2);
153 EXPECT_TRUE(range.Contains(6));
154}
155
156TEST(TextRange, ContainsPostEndPositionReversed) {
157 TextRange range(6, 2);
158 EXPECT_FALSE(range.Contains(7));
159}
160
161TEST(TextRange, ContainsRangePreStartPosition) {
162 TextRange range(2, 6);
163 EXPECT_FALSE(range.Contains(TextRange(0, 1)));
164}
165
166TEST(TextRange, ContainsRangeSpanningStartPosition) {
167 TextRange range(2, 6);
168 EXPECT_FALSE(range.Contains(TextRange(1, 3)));
169}
170
171TEST(TextRange, ContainsRangeStartPosition) {
172 TextRange range(2, 6);
173 EXPECT_TRUE(range.Contains(TextRange(2)));
174}
175
176TEST(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
182TEST(TextRange, ContainsRangeEndPosition) {
183 TextRange range(2, 6);
184 EXPECT_TRUE(range.Contains(TextRange(6)));
185}
186
187TEST(TextRange, ContainsRangeSpanningEndPosition) {
188 TextRange range(2, 6);
189 EXPECT_FALSE(range.Contains(TextRange(5, 7)));
190}
191
192TEST(TextRange, ContainsRangePostEndPosition) {
193 TextRange range(2, 6);
194 EXPECT_FALSE(range.Contains(TextRange(6, 7)));
195}
196
197TEST(TextRange, ContainsRangePreStartPositionReversed) {
198 TextRange range(6, 2);
199 EXPECT_FALSE(range.Contains(TextRange(0, 1)));
200}
201
202TEST(TextRange, ContainsRangeSpanningStartPositionReversed) {
203 TextRange range(6, 2);
204 EXPECT_FALSE(range.Contains(TextRange(1, 3)));
205}
206
207TEST(TextRange, ContainsRangeStartPositionReversed) {
208 TextRange range(6, 2);
209 EXPECT_TRUE(range.Contains(TextRange(2)));
210}
211
212TEST(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
218TEST(TextRange, ContainsRangeSpanningEndPositionReversed) {
219 TextRange range(6, 2);
220 EXPECT_FALSE(range.Contains(TextRange(5, 7)));
221}
222
223TEST(TextRange, ContainsRangeEndPositionReversed) {
224 TextRange range(6, 2);
225 EXPECT_TRUE(range.Contains(TextRange(5)));
226}
227
228TEST(TextRange, ContainsRangePostEndPositionReversed) {
229 TextRange range(6, 2);
230 EXPECT_FALSE(range.Contains(TextRange(6, 7)));
231}
232
233TEST(TextRange, ReversedForwardRange) {
234 TextRange range(2, 6);
235 EXPECT_FALSE(range.reversed());
236}
237
238TEST(TextRange, ReversedCollapsedRange) {
239 TextRange range(2, 2);
240 EXPECT_FALSE(range.reversed());
241}
242
243TEST(TextRange, ReversedReversedRange) {
244 TextRange range(6, 2);
245 EXPECT_TRUE(range.reversed());
246}
247
248} // namespace flutter
void set_end(size_t pos)
Definition: text_range.h:57
bool reversed() const
Definition: text_range.h:80
size_t position() const
Definition: text_range.h:68
void set_extent(size_t pos)
Definition: text_range.h:39
void set_base(size_t pos)
Definition: text_range.h:33
bool Contains(size_t position) const
Definition: text_range.h:83
size_t start() const
Definition: text_range.h:42
size_t base() const
Definition: text_range.h:30
bool collapsed() const
Definition: text_range.h:77
size_t length() const
Definition: text_range.h:74
size_t extent() const
Definition: text_range.h:36
void set_start(size_t pos)
Definition: text_range.h:45
size_t end() const
Definition: text_range.h:54
TEST(FrameTimingsRecorderTest, RecordVsync)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678