Flutter Engine
The Flutter Engine
text_input_model_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_input_model.h"
6
7#include <limits>
8#include <map>
9#include <vector>
10
11#include "gtest/gtest.h"
12
13namespace flutter {
14
16 auto model = std::make_unique<TextInputModel>();
17 model->SetText("ABCDE");
18 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
19}
20
21TEST(TextInputModel, SetTextWideCharacters) {
22 auto model = std::make_unique<TextInputModel>();
23 model->SetText("😄🙃🤪🧐");
24 EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
25}
26
27TEST(TextInputModel, SetTextEmpty) {
28 auto model = std::make_unique<TextInputModel>();
29 model->SetText("");
30 EXPECT_STREQ(model->GetText().c_str(), "");
31}
32
33TEST(TextInputModel, SetTextReplaceText) {
34 auto model = std::make_unique<TextInputModel>();
35 model->SetText("ABCDE");
36 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
37 model->SetText("");
38 EXPECT_STREQ(model->GetText().c_str(), "");
39}
40
41TEST(TextInputModel, SetTextResetsSelection) {
42 auto model = std::make_unique<TextInputModel>();
43 model->SetText("ABCDE");
44 EXPECT_TRUE(model->SetSelection(TextRange(3)));
45 EXPECT_EQ(model->selection(), TextRange(3));
46 model->SetText("FGHJI");
47 EXPECT_EQ(model->selection(), TextRange(0));
48}
49
50TEST(TextInputModel, SetSelectionStart) {
51 auto model = std::make_unique<TextInputModel>();
52 model->SetText("ABCDE");
53 EXPECT_TRUE(model->SetSelection(TextRange(0)));
54 EXPECT_EQ(model->selection(), TextRange(0));
55 EXPECT_EQ(model->composing_range(), TextRange(0));
56 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
57}
58
59TEST(TextInputModel, SetSelectionComposingStart) {
60 auto model = std::make_unique<TextInputModel>();
61 model->SetText("ABCDE");
62 model->BeginComposing();
63 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
64 EXPECT_TRUE(model->SetSelection(TextRange(1)));
65 EXPECT_EQ(model->selection(), TextRange(1));
66 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
67 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
68}
69
70TEST(TextInputModel, SetSelectionMiddle) {
71 auto model = std::make_unique<TextInputModel>();
72 model->SetText("ABCDE");
73 EXPECT_TRUE(model->SetSelection(TextRange(2)));
74 EXPECT_EQ(model->selection(), TextRange(2));
75 EXPECT_EQ(model->composing_range(), TextRange(0));
76 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
77}
78
79TEST(TextInputModel, SetSelectionComposingMiddle) {
80 auto model = std::make_unique<TextInputModel>();
81 model->SetText("ABCDE");
82 model->BeginComposing();
83 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
84 EXPECT_TRUE(model->SetSelection(TextRange(2)));
85 EXPECT_EQ(model->selection(), TextRange(2));
86 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
87 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
88}
89
90TEST(TextInputModel, SetSelectionEnd) {
91 auto model = std::make_unique<TextInputModel>();
92 model->SetText("ABCDE");
93 EXPECT_TRUE(model->SetSelection(TextRange(5)));
94 EXPECT_EQ(model->selection(), TextRange(5));
95 EXPECT_EQ(model->composing_range(), TextRange(0));
96 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
97}
98
99TEST(TextInputModel, SetSelectionComposingEnd) {
100 auto model = std::make_unique<TextInputModel>();
101 model->SetText("ABCDE");
102 model->BeginComposing();
103 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
104 EXPECT_TRUE(model->SetSelection(TextRange(4)));
105 EXPECT_EQ(model->selection(), TextRange(4));
106 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
107 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
108}
109
110TEST(TextInputModel, SetSelectionWthExtent) {
111 auto model = std::make_unique<TextInputModel>();
112 model->SetText("ABCDE");
113 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
114 EXPECT_EQ(model->selection(), TextRange(1, 4));
115 EXPECT_EQ(model->composing_range(), TextRange(0));
116 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
117}
118
119TEST(TextInputModel, SetSelectionWthExtentComposing) {
120 auto model = std::make_unique<TextInputModel>();
121 model->SetText("ABCDE");
122 model->BeginComposing();
123 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
124 EXPECT_FALSE(model->SetSelection(TextRange(1, 4)));
125 EXPECT_EQ(model->selection(), TextRange(1));
126 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
127 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
128}
129
130TEST(TextInputModel, SetSelectionReverseExtent) {
131 auto model = std::make_unique<TextInputModel>();
132 model->SetText("ABCDE");
133 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
134 EXPECT_EQ(model->selection(), TextRange(4, 1));
135 EXPECT_EQ(model->composing_range(), TextRange(0));
136 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
137}
138
139TEST(TextInputModel, SetSelectionReverseExtentComposing) {
140 auto model = std::make_unique<TextInputModel>();
141 model->SetText("ABCDE");
142 model->BeginComposing();
143 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
144 EXPECT_FALSE(model->SetSelection(TextRange(4, 1)));
145 EXPECT_EQ(model->selection(), TextRange(1));
146 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
147 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
148}
149
150TEST(TextInputModel, SetSelectionOutsideString) {
151 auto model = std::make_unique<TextInputModel>();
152 model->SetText("ABCDE");
153 EXPECT_FALSE(model->SetSelection(TextRange(4, 6)));
154 EXPECT_FALSE(model->SetSelection(TextRange(5, 6)));
155 EXPECT_FALSE(model->SetSelection(TextRange(6)));
156}
157
158TEST(TextInputModel, SetSelectionOutsideComposingRange) {
159 auto model = std::make_unique<TextInputModel>();
160 model->SetText("ABCDE");
161 model->BeginComposing();
162 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
163 EXPECT_FALSE(model->SetSelection(TextRange(0)));
164 EXPECT_EQ(model->selection(), TextRange(1));
165 EXPECT_FALSE(model->SetSelection(TextRange(5)));
166 EXPECT_EQ(model->selection(), TextRange(1));
167 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
168}
169
170TEST(TextInputModel, SetComposingRangeStart) {
171 auto model = std::make_unique<TextInputModel>();
172 model->SetText("ABCDE");
173 model->BeginComposing();
174 EXPECT_TRUE(model->SetComposingRange(TextRange(0, 0), 0));
175 EXPECT_EQ(model->selection(), TextRange(0));
176 EXPECT_EQ(model->composing_range(), TextRange(0));
177 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
178}
179
180TEST(TextInputModel, SetComposingRangeMiddle) {
181 auto model = std::make_unique<TextInputModel>();
182 model->SetText("ABCDE");
183 model->BeginComposing();
184 EXPECT_TRUE(model->SetComposingRange(TextRange(2, 2), 0));
185 EXPECT_EQ(model->selection(), TextRange(2));
186 EXPECT_EQ(model->composing_range(), TextRange(2));
187 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
188}
189
190TEST(TextInputModel, SetComposingRangeEnd) {
191 auto model = std::make_unique<TextInputModel>();
192 model->SetText("ABCDE");
193 model->BeginComposing();
194 EXPECT_TRUE(model->SetComposingRange(TextRange(5, 5), 0));
195 EXPECT_EQ(model->selection(), TextRange(5));
196 EXPECT_EQ(model->composing_range(), TextRange(5));
197 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
198}
199
200TEST(TextInputModel, SetComposingRangeWithExtent) {
201 auto model = std::make_unique<TextInputModel>();
202 model->SetText("ABCDE");
203 model->BeginComposing();
204 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
205 EXPECT_EQ(model->selection(), TextRange(4));
206 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
207 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
208}
209
210TEST(TextInputModel, SetComposingRangeReverseExtent) {
211 auto model = std::make_unique<TextInputModel>();
212 model->SetText("ABCDE");
213 model->BeginComposing();
214 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
215 EXPECT_EQ(model->selection(), TextRange(4));
216 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
217 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
218}
219
220TEST(TextInputModel, SetComposingRangeOutsideString) {
221 auto model = std::make_unique<TextInputModel>();
222 model->SetText("ABCDE");
223 model->BeginComposing();
224 EXPECT_FALSE(model->SetComposingRange(TextRange(4, 6), 0));
225 EXPECT_FALSE(model->SetComposingRange(TextRange(5, 6), 0));
226 EXPECT_FALSE(model->SetComposingRange(TextRange(6, 6), 0));
227}
228
229// Composing sequence with no initial selection and no text input.
230TEST(TextInputModel, CommitComposingNoTextWithNoSelection) {
231 auto model = std::make_unique<TextInputModel>();
232 model->SetText("ABCDE");
233 model->SetSelection(TextRange(0));
234
235 // Verify no changes on BeginComposing.
236 model->BeginComposing();
237 EXPECT_EQ(model->selection(), TextRange(0));
238 EXPECT_EQ(model->composing_range(), TextRange(0));
239 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
240
241 // Verify no changes on CommitComposing.
242 model->CommitComposing();
243 EXPECT_EQ(model->selection(), TextRange(0));
244 EXPECT_EQ(model->composing_range(), TextRange(0));
245 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
246
247 // Verify no changes on CommitComposing.
248 model->EndComposing();
249 EXPECT_EQ(model->selection(), TextRange(0));
250 EXPECT_EQ(model->composing_range(), TextRange(0));
251 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
252}
253
254// Composing sequence with an initial selection and no text input.
255TEST(TextInputModel, CommitComposingNoTextWithSelection) {
256 auto model = std::make_unique<TextInputModel>();
257 model->SetText("ABCDE");
258 model->SetSelection(TextRange(1, 3));
259
260 // Verify no changes on BeginComposing.
261 model->BeginComposing();
262 EXPECT_EQ(model->selection(), TextRange(1, 3));
263 EXPECT_EQ(model->composing_range(), TextRange(1));
264 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
265
266 // Verify no changes on CommitComposing.
267 model->CommitComposing();
268 EXPECT_EQ(model->selection(), TextRange(1, 3));
269 EXPECT_EQ(model->composing_range(), TextRange(1));
270 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
271
272 // Verify no changes on CommitComposing.
273 model->EndComposing();
274 EXPECT_EQ(model->selection(), TextRange(1, 3));
275 EXPECT_EQ(model->composing_range(), TextRange(0));
276 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
277}
278
279// Composing sequence with no initial selection.
280TEST(TextInputModel, CommitComposingTextWithNoSelection) {
281 auto model = std::make_unique<TextInputModel>();
282 model->SetText("ABCDE");
283 model->SetSelection(TextRange(1));
284
285 // Verify no changes on BeginComposing.
286 model->BeginComposing();
287 EXPECT_EQ(model->selection(), TextRange(1));
288 EXPECT_EQ(model->composing_range(), TextRange(1));
289 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
290
291 // Verify selection base, extent and composing extent increment as text is
292 // entered. Verify composing base does not change.
293 model->UpdateComposingText("つ");
294 EXPECT_EQ(model->selection(), TextRange(2));
295 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
296 EXPECT_STREQ(model->GetText().c_str(), "AつBCDE");
297 model->UpdateComposingText("つる");
298 EXPECT_EQ(model->selection(), TextRange(3));
299 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
300 EXPECT_STREQ(model->GetText().c_str(), "AつるBCDE");
301
302 // Verify that cursor position is set to correct offset from composing base.
303 model->UpdateComposingText("鶴");
304 EXPECT_TRUE(model->SetSelection(TextRange(1)));
305 EXPECT_EQ(model->selection(), TextRange(1));
306 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
307 EXPECT_STREQ(model->GetText().c_str(), "A鶴BCDE");
308
309 // Verify composing base is set to composing extent on commit.
310 model->CommitComposing();
311 EXPECT_EQ(model->selection(), TextRange(2));
312 EXPECT_EQ(model->composing_range(), TextRange(2));
313 EXPECT_STREQ(model->GetText().c_str(), "A鶴BCDE");
314
315 // Verify that further text entry increments the selection base, extent and
316 // the composing extent. Verify that composing base does not change.
317 model->UpdateComposingText("が");
318 EXPECT_EQ(model->selection(), TextRange(3));
319 EXPECT_EQ(model->composing_range(), TextRange(2, 3));
320 EXPECT_STREQ(model->GetText().c_str(), "A鶴がBCDE");
321
322 // Verify composing base is set to composing extent on commit.
323 model->CommitComposing();
324 EXPECT_EQ(model->selection(), TextRange(3));
325 EXPECT_EQ(model->composing_range(), TextRange(3));
326 EXPECT_STREQ(model->GetText().c_str(), "A鶴がBCDE");
327
328 // Verify no changes on EndComposing.
329 model->EndComposing();
330 EXPECT_EQ(model->selection(), TextRange(3));
331 EXPECT_EQ(model->composing_range(), TextRange(0));
332 EXPECT_STREQ(model->GetText().c_str(), "A鶴がBCDE");
333}
334
335// Composing sequence with an initial selection.
336TEST(TextInputModel, CommitComposingTextWithSelection) {
337 auto model = std::make_unique<TextInputModel>();
338 model->SetText("ABCDE");
339 model->SetSelection(TextRange(1, 3));
340
341 // Verify no changes on BeginComposing.
342 model->BeginComposing();
343 EXPECT_EQ(model->selection(), TextRange(1, 3));
344 EXPECT_EQ(model->composing_range(), TextRange(1));
345 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
346
347 // Verify selection is replaced and selection base, extent and composing
348 // extent increment to the position immediately after the composing text.
349 // Verify composing base does not change.
350 model->UpdateComposingText("つ");
351 EXPECT_EQ(model->selection(), TextRange(2));
352 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
353 EXPECT_STREQ(model->GetText().c_str(), "AつDE");
354
355 // Verify that further text entry increments the selection base, extent and
356 // the composing extent. Verify that composing base does not change.
357 model->UpdateComposingText("つる");
358 EXPECT_EQ(model->selection(), TextRange(3));
359 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
360 EXPECT_STREQ(model->GetText().c_str(), "AつるDE");
361
362 // Verify that cursor position is set to correct offset from composing base.
363 model->UpdateComposingText("鶴");
364 EXPECT_TRUE(model->SetSelection(TextRange(1)));
365 EXPECT_EQ(model->selection(), TextRange(1));
366 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
367 EXPECT_STREQ(model->GetText().c_str(), "A鶴DE");
368
369 // Verify composing base is set to composing extent on commit.
370 model->CommitComposing();
371 EXPECT_EQ(model->selection(), TextRange(2));
372 EXPECT_EQ(model->composing_range(), TextRange(2));
373 EXPECT_STREQ(model->GetText().c_str(), "A鶴DE");
374
375 // Verify that further text entry increments the selection base, extent and
376 // the composing extent. Verify that composing base does not change.
377 model->UpdateComposingText("が");
378 EXPECT_EQ(model->selection(), TextRange(3));
379 EXPECT_EQ(model->composing_range(), TextRange(2, 3));
380 EXPECT_STREQ(model->GetText().c_str(), "A鶴がDE");
381
382 // Verify composing base is set to composing extent on commit.
383 model->CommitComposing();
384 EXPECT_EQ(model->selection(), TextRange(3));
385 EXPECT_EQ(model->composing_range(), TextRange(3));
386 EXPECT_STREQ(model->GetText().c_str(), "A鶴がDE");
387
388 // Verify no changes on EndComposing.
389 model->EndComposing();
390 EXPECT_EQ(model->selection(), TextRange(3));
391 EXPECT_EQ(model->composing_range(), TextRange(0));
392 EXPECT_STREQ(model->GetText().c_str(), "A鶴がDE");
393}
394
395TEST(TextInputModel, UpdateComposingRemovesLastComposingCharacter) {
396 auto model = std::make_unique<TextInputModel>();
397 model->SetText("ABCDE");
398 model->BeginComposing();
399 model->SetComposingRange(TextRange(1, 2), 1);
400 model->UpdateComposingText("");
401 EXPECT_EQ(model->selection(), TextRange(1));
402 EXPECT_EQ(model->composing_range(), TextRange(1));
403 model->SetText("ACDE");
404}
405
406TEST(TextInputModel, UpdateSelectionWhileComposing) {
407 auto model = std::make_unique<TextInputModel>();
408 model->SetText("ABCDE");
409 model->BeginComposing();
410 model->SetComposingRange(TextRange(4, 5), 1);
411 model->UpdateComposingText(u"ぴょんぴょん", TextRange(3, 6));
412 EXPECT_STREQ(model->GetText().c_str(), "ABCDぴょんぴょん");
413 EXPECT_EQ(model->selection(), TextRange(7, 10));
414 EXPECT_EQ(model->composing_range(), TextRange(4, 10));
415}
416
417TEST(TextInputModel, AddCodePoint) {
418 auto model = std::make_unique<TextInputModel>();
419 model->AddCodePoint('A');
420 model->AddCodePoint('B');
421 model->AddCodePoint(0x1f604);
422 model->AddCodePoint('D');
423 model->AddCodePoint('E');
424 EXPECT_EQ(model->selection(), TextRange(6));
425 EXPECT_EQ(model->composing_range(), TextRange(0));
426 EXPECT_STREQ(model->GetText().c_str(), "AB😄DE");
427}
428
429TEST(TextInputModel, AddCodePointSelection) {
430 auto model = std::make_unique<TextInputModel>();
431 model->SetText("ABCDE");
432 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
433 model->AddCodePoint('x');
434 EXPECT_EQ(model->selection(), TextRange(2));
435 EXPECT_EQ(model->composing_range(), TextRange(0));
436 EXPECT_STREQ(model->GetText().c_str(), "AxE");
437}
438
439TEST(TextInputModel, AddCodePointReverseSelection) {
440 auto model = std::make_unique<TextInputModel>();
441 model->SetText("ABCDE");
442 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
443 model->AddCodePoint('x');
444 EXPECT_EQ(model->selection(), TextRange(2));
445 EXPECT_EQ(model->composing_range(), TextRange(0));
446 EXPECT_STREQ(model->GetText().c_str(), "AxE");
447}
448
449TEST(TextInputModel, AddCodePointSelectionWideCharacter) {
450 auto model = std::make_unique<TextInputModel>();
451 model->SetText("ABCDE");
452 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
453 model->AddCodePoint(0x1f604);
454 EXPECT_EQ(model->selection(), TextRange(3));
455 EXPECT_EQ(model->composing_range(), TextRange(0));
456 EXPECT_STREQ(model->GetText().c_str(), "A😄E");
457}
458
459TEST(TextInputModel, AddCodePointReverseSelectionWideCharacter) {
460 auto model = std::make_unique<TextInputModel>();
461 model->SetText("ABCDE");
462 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
463 model->AddCodePoint(0x1f604);
464 EXPECT_EQ(model->selection(), TextRange(3));
465 EXPECT_EQ(model->composing_range(), TextRange(0));
466 EXPECT_STREQ(model->GetText().c_str(), "A😄E");
467}
468
470 auto model = std::make_unique<TextInputModel>();
471 model->AddText(u"ABCDE");
472 model->AddText("😄");
473 model->AddText("FGHIJ");
474 EXPECT_EQ(model->selection(), TextRange(12));
475 EXPECT_EQ(model->composing_range(), TextRange(0));
476 EXPECT_STREQ(model->GetText().c_str(), "ABCDE😄FGHIJ");
477}
478
479TEST(TextInputModel, AddTextSelection) {
480 auto model = std::make_unique<TextInputModel>();
481 model->SetText("ABCDE");
482 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
483 model->AddText("xy");
484 EXPECT_EQ(model->selection(), TextRange(3));
485 EXPECT_EQ(model->composing_range(), TextRange(0));
486 EXPECT_STREQ(model->GetText().c_str(), "AxyE");
487}
488
489TEST(TextInputModel, AddTextReverseSelection) {
490 auto model = std::make_unique<TextInputModel>();
491 model->SetText("ABCDE");
492 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
493 model->AddText("xy");
494 EXPECT_EQ(model->selection(), TextRange(3));
495 EXPECT_EQ(model->composing_range(), TextRange(0));
496 EXPECT_STREQ(model->GetText().c_str(), "AxyE");
497}
498
499TEST(TextInputModel, AddTextSelectionWideCharacter) {
500 auto model = std::make_unique<TextInputModel>();
501 model->SetText("ABCDE");
502 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
503 model->AddText(u"😄🙃");
504 EXPECT_EQ(model->selection(), TextRange(5));
505 EXPECT_EQ(model->composing_range(), TextRange(0));
506 EXPECT_STREQ(model->GetText().c_str(), "A😄🙃E");
507}
508
509TEST(TextInputModel, AddTextReverseSelectionWideCharacter) {
510 auto model = std::make_unique<TextInputModel>();
511 model->SetText("ABCDE");
512 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
513 model->AddText(u"😄🙃");
514 EXPECT_EQ(model->selection(), TextRange(5));
515 EXPECT_EQ(model->composing_range(), TextRange(0));
516 EXPECT_STREQ(model->GetText().c_str(), "A😄🙃E");
517}
518
519TEST(TextInputModel, DeleteStart) {
520 auto model = std::make_unique<TextInputModel>();
521 model->SetText("ABCDE");
522 EXPECT_TRUE(model->SetSelection(TextRange(0)));
523 ASSERT_TRUE(model->Delete());
524 EXPECT_EQ(model->selection(), TextRange(0));
525 EXPECT_EQ(model->composing_range(), TextRange(0));
526 EXPECT_STREQ(model->GetText().c_str(), "BCDE");
527}
528
529TEST(TextInputModel, DeleteMiddle) {
530 auto model = std::make_unique<TextInputModel>();
531 model->SetText("ABCDE");
532 EXPECT_TRUE(model->SetSelection(TextRange(2)));
533 ASSERT_TRUE(model->Delete());
534 EXPECT_EQ(model->selection(), TextRange(2));
535 EXPECT_EQ(model->composing_range(), TextRange(0));
536 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
537}
538
539TEST(TextInputModel, DeleteEnd) {
540 auto model = std::make_unique<TextInputModel>();
541 model->SetText("ABCDE");
542 EXPECT_TRUE(model->SetSelection(TextRange(5)));
543 ASSERT_FALSE(model->Delete());
544 EXPECT_EQ(model->selection(), TextRange(5));
545 EXPECT_EQ(model->composing_range(), TextRange(0));
546 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
547}
548
549TEST(TextInputModel, DeleteWideCharacters) {
550 auto model = std::make_unique<TextInputModel>();
551 model->SetText("😄🙃🤪🧐");
552 EXPECT_TRUE(model->SetSelection(TextRange(4)));
553 ASSERT_TRUE(model->Delete());
554 EXPECT_EQ(model->selection(), TextRange(4));
555 EXPECT_EQ(model->composing_range(), TextRange(0));
556 EXPECT_STREQ(model->GetText().c_str(), "😄🙃🧐");
557}
558
559TEST(TextInputModel, DeleteSelection) {
560 auto model = std::make_unique<TextInputModel>();
561 model->SetText("ABCDE");
562 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
563 ASSERT_TRUE(model->Delete());
564 EXPECT_EQ(model->selection(), TextRange(1));
565 EXPECT_EQ(model->composing_range(), TextRange(0));
566 EXPECT_STREQ(model->GetText().c_str(), "AE");
567}
568
569TEST(TextInputModel, DeleteReverseSelection) {
570 auto model = std::make_unique<TextInputModel>();
571 model->SetText("ABCDE");
572 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
573 ASSERT_TRUE(model->Delete());
574 EXPECT_EQ(model->selection(), TextRange(1));
575 EXPECT_EQ(model->composing_range(), TextRange(0));
576 EXPECT_STREQ(model->GetText().c_str(), "AE");
577}
578
579TEST(TextInputModel, DeleteStartComposing) {
580 auto model = std::make_unique<TextInputModel>();
581 model->SetText("ABCDE");
582 model->BeginComposing();
583 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
584 EXPECT_EQ(model->selection(), TextRange(1));
585 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
586 ASSERT_TRUE(model->Delete());
587 EXPECT_EQ(model->selection(), TextRange(1));
588 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
589 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
590}
591
592TEST(TextInputModel, DeleteStartReverseComposing) {
593 auto model = std::make_unique<TextInputModel>();
594 model->SetText("ABCDE");
595 model->BeginComposing();
596 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
597 EXPECT_EQ(model->selection(), TextRange(1));
598 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
599 ASSERT_TRUE(model->Delete());
600 EXPECT_EQ(model->selection(), TextRange(1));
601 EXPECT_EQ(model->composing_range(), TextRange(3, 1));
602 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
603}
604
605TEST(TextInputModel, DeleteMiddleComposing) {
606 auto model = std::make_unique<TextInputModel>();
607 model->SetText("ABCDE");
608 model->BeginComposing();
609 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
610 ASSERT_TRUE(model->Delete());
611 EXPECT_EQ(model->selection(), TextRange(2));
612 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
613 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
614}
615
616TEST(TextInputModel, DeleteMiddleReverseComposing) {
617 auto model = std::make_unique<TextInputModel>();
618 model->SetText("ABCDE");
619 model->BeginComposing();
620 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
621 ASSERT_TRUE(model->Delete());
622 EXPECT_EQ(model->selection(), TextRange(2));
623 EXPECT_EQ(model->composing_range(), TextRange(3, 1));
624 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
625}
626
627TEST(TextInputModel, DeleteEndComposing) {
628 auto model = std::make_unique<TextInputModel>();
629 model->SetText("ABCDE");
630 model->BeginComposing();
631 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
632 ASSERT_FALSE(model->Delete());
633 EXPECT_EQ(model->selection(), TextRange(4));
634 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
635 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
636}
637
638TEST(TextInputModel, DeleteEndReverseComposing) {
639 auto model = std::make_unique<TextInputModel>();
640 model->SetText("ABCDE");
641 model->BeginComposing();
642 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
643 ASSERT_FALSE(model->Delete());
644 EXPECT_EQ(model->selection(), TextRange(4));
645 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
646 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
647}
648
649TEST(TextInputModel, DeleteSurroundingAtCursor) {
650 auto model = std::make_unique<TextInputModel>();
651 model->SetText("ABCDE");
652 EXPECT_TRUE(model->SetSelection(TextRange(2)));
653 EXPECT_TRUE(model->DeleteSurrounding(0, 1));
654 EXPECT_EQ(model->selection(), TextRange(2));
655 EXPECT_EQ(model->composing_range(), TextRange(0));
656 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
657}
658
659TEST(TextInputModel, DeleteSurroundingAtCursorComposing) {
660 auto model = std::make_unique<TextInputModel>();
661 model->SetText("ABCDE");
662 model->BeginComposing();
663 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
664 EXPECT_TRUE(model->DeleteSurrounding(0, 1));
665 EXPECT_EQ(model->selection(), TextRange(2));
666 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
667 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
668}
669
670TEST(TextInputModel, DeleteSurroundingAtCursorAll) {
671 auto model = std::make_unique<TextInputModel>();
672 model->SetText("ABCDE");
673 EXPECT_TRUE(model->SetSelection(TextRange(2)));
674 EXPECT_TRUE(model->DeleteSurrounding(0, 3));
675 EXPECT_EQ(model->selection(), TextRange(2));
676 EXPECT_EQ(model->composing_range(), TextRange(0));
677 EXPECT_STREQ(model->GetText().c_str(), "AB");
678}
679
680TEST(TextInputModel, DeleteSurroundingAtCursorAllComposing) {
681 auto model = std::make_unique<TextInputModel>();
682 model->SetText("ABCDE");
683 model->BeginComposing();
684 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
685 EXPECT_TRUE(model->DeleteSurrounding(0, 2));
686 EXPECT_EQ(model->selection(), TextRange(2));
687 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
688 EXPECT_STREQ(model->GetText().c_str(), "ABE");
689}
690
691TEST(TextInputModel, DeleteSurroundingAtCursorGreedy) {
692 auto model = std::make_unique<TextInputModel>();
693 model->SetText("ABCDE");
694 EXPECT_TRUE(model->SetSelection(TextRange(2)));
695 EXPECT_TRUE(model->DeleteSurrounding(0, 4));
696 EXPECT_EQ(model->selection(), TextRange(2));
697 EXPECT_EQ(model->composing_range(), TextRange(0));
698 EXPECT_STREQ(model->GetText().c_str(), "AB");
699}
700
701TEST(TextInputModel, DeleteSurroundingAtCursorGreedyComposing) {
702 auto model = std::make_unique<TextInputModel>();
703 model->SetText("ABCDE");
704 model->BeginComposing();
705 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
706 EXPECT_TRUE(model->DeleteSurrounding(0, 4));
707 EXPECT_EQ(model->selection(), TextRange(2));
708 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
709 EXPECT_STREQ(model->GetText().c_str(), "ABE");
710}
711
712TEST(TextInputModel, DeleteSurroundingBeforeCursor) {
713 auto model = std::make_unique<TextInputModel>();
714 model->SetText("ABCDE");
715 EXPECT_TRUE(model->SetSelection(TextRange(2)));
716 EXPECT_TRUE(model->DeleteSurrounding(-1, 1));
717 EXPECT_EQ(model->selection(), TextRange(1));
718 EXPECT_EQ(model->composing_range(), TextRange(0));
719 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
720}
721
722TEST(TextInputModel, DeleteSurroundingBeforeCursorComposing) {
723 auto model = std::make_unique<TextInputModel>();
724 model->SetText("ABCDE");
725 model->BeginComposing();
726 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
727 EXPECT_TRUE(model->DeleteSurrounding(-1, 1));
728 EXPECT_EQ(model->selection(), TextRange(2));
729 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
730 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
731}
732
733TEST(TextInputModel, DeleteSurroundingBeforeCursorAll) {
734 auto model = std::make_unique<TextInputModel>();
735 model->SetText("ABCDE");
736 EXPECT_TRUE(model->SetSelection(TextRange(2)));
737 EXPECT_TRUE(model->DeleteSurrounding(-2, 2));
738 EXPECT_EQ(model->selection(), TextRange(0));
739 EXPECT_EQ(model->composing_range(), TextRange(0));
740 EXPECT_STREQ(model->GetText().c_str(), "CDE");
741}
742
743TEST(TextInputModel, DeleteSurroundingBeforeCursorAllComposing) {
744 auto model = std::make_unique<TextInputModel>();
745 model->SetText("ABCDE");
746 model->BeginComposing();
747 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
748 EXPECT_TRUE(model->DeleteSurrounding(-2, 2));
749 EXPECT_EQ(model->selection(), TextRange(1));
750 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
751 EXPECT_STREQ(model->GetText().c_str(), "ADE");
752}
753
754TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedy) {
755 auto model = std::make_unique<TextInputModel>();
756 model->SetText("ABCDE");
757 EXPECT_TRUE(model->SetSelection(TextRange(2)));
758 EXPECT_TRUE(model->DeleteSurrounding(-3, 3));
759 EXPECT_EQ(model->selection(), TextRange(0));
760 EXPECT_EQ(model->composing_range(), TextRange(0));
761 EXPECT_STREQ(model->GetText().c_str(), "CDE");
762}
763
764TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedyComposing) {
765 auto model = std::make_unique<TextInputModel>();
766 model->SetText("ABCDE");
767 model->BeginComposing();
768 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
769 EXPECT_TRUE(model->DeleteSurrounding(-3, 3));
770 EXPECT_EQ(model->selection(), TextRange(1));
771 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
772 EXPECT_STREQ(model->GetText().c_str(), "ADE");
773}
774
775TEST(TextInputModel, DeleteSurroundingAfterCursor) {
776 auto model = std::make_unique<TextInputModel>();
777 model->SetText("ABCDE");
778 EXPECT_TRUE(model->SetSelection(TextRange(2)));
779 EXPECT_TRUE(model->DeleteSurrounding(1, 1));
780 EXPECT_EQ(model->selection(), TextRange(2));
781 EXPECT_EQ(model->composing_range(), TextRange(0));
782 EXPECT_STREQ(model->GetText().c_str(), "ABCE");
783}
784
785TEST(TextInputModel, DeleteSurroundingAfterCursorComposing) {
786 auto model = std::make_unique<TextInputModel>();
787 model->SetText("ABCDE");
788 model->BeginComposing();
789 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
790 EXPECT_TRUE(model->DeleteSurrounding(1, 1));
791 EXPECT_EQ(model->selection(), TextRange(1));
792 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
793 EXPECT_STREQ(model->GetText().c_str(), "ABDE");
794}
795
796TEST(TextInputModel, DeleteSurroundingAfterCursorAll) {
797 auto model = std::make_unique<TextInputModel>();
798 model->SetText("ABCDE");
799 EXPECT_TRUE(model->SetSelection(TextRange(2)));
800 EXPECT_TRUE(model->DeleteSurrounding(1, 2));
801 EXPECT_EQ(model->selection(), TextRange(2));
802 EXPECT_EQ(model->composing_range(), TextRange(0));
803 EXPECT_STREQ(model->GetText().c_str(), "ABC");
804}
805
806TEST(TextInputModel, DeleteSurroundingAfterCursorAllComposing) {
807 auto model = std::make_unique<TextInputModel>();
808 model->SetText("ABCDE");
809 model->BeginComposing();
810 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
811 EXPECT_TRUE(model->DeleteSurrounding(1, 2));
812 EXPECT_EQ(model->selection(), TextRange(1));
813 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
814 EXPECT_STREQ(model->GetText().c_str(), "ABE");
815}
816
817TEST(TextInputModel, DeleteSurroundingAfterCursorGreedy) {
818 auto model = std::make_unique<TextInputModel>();
819 model->SetText("ABCDE");
820 EXPECT_TRUE(model->SetSelection(TextRange(2)));
821 EXPECT_TRUE(model->DeleteSurrounding(1, 3));
822 EXPECT_EQ(model->selection(), TextRange(2));
823 EXPECT_EQ(model->composing_range(), TextRange(0));
824 EXPECT_STREQ(model->GetText().c_str(), "ABC");
825}
826
827TEST(TextInputModel, DeleteSurroundingAfterCursorGreedyComposing) {
828 auto model = std::make_unique<TextInputModel>();
829 model->SetText("ABCDE");
830 model->BeginComposing();
831 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
832 EXPECT_TRUE(model->DeleteSurrounding(1, 3));
833 EXPECT_EQ(model->selection(), TextRange(1));
834 EXPECT_EQ(model->composing_range(), TextRange(1, 2));
835 EXPECT_STREQ(model->GetText().c_str(), "ABE");
836}
837
838TEST(TextInputModel, DeleteSurroundingSelection) {
839 auto model = std::make_unique<TextInputModel>();
840 model->SetText("ABCDE");
841 EXPECT_TRUE(model->SetSelection(TextRange(2, 3)));
842 EXPECT_TRUE(model->DeleteSurrounding(0, 1));
843 EXPECT_EQ(model->selection(), TextRange(3));
844 EXPECT_EQ(model->composing_range(), TextRange(0));
845 EXPECT_STREQ(model->GetText().c_str(), "ABCE");
846}
847
848TEST(TextInputModel, DeleteSurroundingReverseSelection) {
849 auto model = std::make_unique<TextInputModel>();
850 model->SetText("ABCDE");
851 EXPECT_TRUE(model->SetSelection(TextRange(4, 3)));
852 EXPECT_TRUE(model->DeleteSurrounding(0, 1));
853 EXPECT_EQ(model->selection(), TextRange(3));
854 EXPECT_EQ(model->composing_range(), TextRange(0));
855 EXPECT_STREQ(model->GetText().c_str(), "ABCE");
856}
857
858TEST(TextInputModel, BackspaceStart) {
859 auto model = std::make_unique<TextInputModel>();
860 model->SetText("ABCDE");
861 EXPECT_TRUE(model->SetSelection(TextRange(0)));
862 ASSERT_FALSE(model->Backspace());
863 EXPECT_EQ(model->selection(), TextRange(0));
864 EXPECT_EQ(model->composing_range(), TextRange(0));
865 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
866}
867
868TEST(TextInputModel, BackspaceMiddle) {
869 auto model = std::make_unique<TextInputModel>();
870 model->SetText("ABCDE");
871 EXPECT_TRUE(model->SetSelection(TextRange(2)));
872 ASSERT_TRUE(model->Backspace());
873 EXPECT_EQ(model->selection(), TextRange(1));
874 EXPECT_EQ(model->composing_range(), TextRange(0));
875 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
876}
877
878TEST(TextInputModel, BackspaceEnd) {
879 auto model = std::make_unique<TextInputModel>();
880 model->SetText("ABCDE");
881 EXPECT_TRUE(model->SetSelection(TextRange(5)));
882 ASSERT_TRUE(model->Backspace());
883 EXPECT_EQ(model->selection(), TextRange(4));
884 EXPECT_EQ(model->composing_range(), TextRange(0));
885 EXPECT_STREQ(model->GetText().c_str(), "ABCD");
886}
887
888TEST(TextInputModel, BackspaceWideCharacters) {
889 auto model = std::make_unique<TextInputModel>();
890 model->SetText("😄🙃🤪🧐");
891 EXPECT_TRUE(model->SetSelection(TextRange(4)));
892 ASSERT_TRUE(model->Backspace());
893 EXPECT_EQ(model->selection(), TextRange(2));
894 EXPECT_EQ(model->composing_range(), TextRange(0));
895 EXPECT_STREQ(model->GetText().c_str(), "😄🤪🧐");
896}
897
898TEST(TextInputModel, BackspaceSelection) {
899 auto model = std::make_unique<TextInputModel>();
900 model->SetText("ABCDE");
901 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
902 ASSERT_TRUE(model->Delete());
903 EXPECT_EQ(model->selection(), TextRange(1));
904 EXPECT_EQ(model->composing_range(), TextRange(0));
905 EXPECT_STREQ(model->GetText().c_str(), "AE");
906}
907
908TEST(TextInputModel, BackspaceReverseSelection) {
909 auto model = std::make_unique<TextInputModel>();
910 model->SetText("ABCDE");
911 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
912 ASSERT_TRUE(model->Delete());
913 EXPECT_EQ(model->selection(), TextRange(1));
914 EXPECT_EQ(model->composing_range(), TextRange(0));
915 EXPECT_STREQ(model->GetText().c_str(), "AE");
916}
917
918TEST(TextInputModel, BackspaceStartComposing) {
919 auto model = std::make_unique<TextInputModel>();
920 model->SetText("ABCDE");
921 model->BeginComposing();
922 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
923 ASSERT_FALSE(model->Backspace());
924 EXPECT_EQ(model->selection(), TextRange(1));
925 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
926 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
927}
928
929TEST(TextInputModel, BackspaceStartReverseComposing) {
930 auto model = std::make_unique<TextInputModel>();
931 model->SetText("ABCDE");
932 model->BeginComposing();
933 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
934 ASSERT_FALSE(model->Backspace());
935 EXPECT_EQ(model->selection(), TextRange(1));
936 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
937 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
938}
939
940TEST(TextInputModel, BackspaceMiddleComposing) {
941 auto model = std::make_unique<TextInputModel>();
942 model->SetText("ABCDE");
943 model->BeginComposing();
944 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
945 ASSERT_TRUE(model->Backspace());
946 EXPECT_EQ(model->selection(), TextRange(1));
947 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
948 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
949}
950
951TEST(TextInputModel, BackspaceMiddleReverseComposing) {
952 auto model = std::make_unique<TextInputModel>();
953 model->SetText("ABCDE");
954 model->BeginComposing();
955 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
956 ASSERT_TRUE(model->Backspace());
957 EXPECT_EQ(model->selection(), TextRange(1));
958 EXPECT_EQ(model->composing_range(), TextRange(3, 1));
959 EXPECT_STREQ(model->GetText().c_str(), "ACDE");
960}
961
962TEST(TextInputModel, BackspaceEndComposing) {
963 auto model = std::make_unique<TextInputModel>();
964 model->SetText("ABCDE");
965 model->BeginComposing();
966 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
967 ASSERT_TRUE(model->Backspace());
968 EXPECT_EQ(model->selection(), TextRange(3));
969 EXPECT_EQ(model->composing_range(), TextRange(1, 3));
970 EXPECT_STREQ(model->GetText().c_str(), "ABCE");
971}
972
973TEST(TextInputModel, BackspaceEndReverseComposing) {
974 auto model = std::make_unique<TextInputModel>();
975 model->SetText("ABCDE");
976 model->BeginComposing();
977 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
978 ASSERT_TRUE(model->Backspace());
979 EXPECT_EQ(model->selection(), TextRange(3));
980 EXPECT_EQ(model->composing_range(), TextRange(3, 1));
981 EXPECT_STREQ(model->GetText().c_str(), "ABCE");
982}
983
984TEST(TextInputModel, MoveCursorForwardStart) {
985 auto model = std::make_unique<TextInputModel>();
986 model->SetText("ABCDE");
987 EXPECT_TRUE(model->SetSelection(TextRange(0)));
988 EXPECT_TRUE(model->MoveCursorForward());
989 EXPECT_EQ(model->selection(), TextRange(1));
990 EXPECT_EQ(model->composing_range(), TextRange(0));
991 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
992}
993
994TEST(TextInputModel, MoveCursorForwardMiddle) {
995 auto model = std::make_unique<TextInputModel>();
996 model->SetText("ABCDE");
997 EXPECT_TRUE(model->SetSelection(TextRange(2)));
998 EXPECT_TRUE(model->MoveCursorForward());
999 EXPECT_EQ(model->selection(), TextRange(3));
1000 EXPECT_EQ(model->composing_range(), TextRange(0));
1001 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1002}
1003
1004TEST(TextInputModel, MoveCursorForwardEnd) {
1005 auto model = std::make_unique<TextInputModel>();
1006 model->SetText("ABCDE");
1007 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1008 EXPECT_FALSE(model->MoveCursorForward());
1009 EXPECT_EQ(model->selection(), TextRange(5));
1010 EXPECT_EQ(model->composing_range(), TextRange(0));
1011 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1012}
1013
1014TEST(TextInputModel, MoveCursorForwardWideCharacters) {
1015 auto model = std::make_unique<TextInputModel>();
1016 model->SetText("😄🙃🤪🧐");
1017 EXPECT_TRUE(model->SetSelection(TextRange(4)));
1018 ASSERT_TRUE(model->MoveCursorForward());
1019 EXPECT_EQ(model->selection(), TextRange(6));
1020 EXPECT_EQ(model->composing_range(), TextRange(0));
1021 EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
1022}
1023
1024TEST(TextInputModel, MoveCursorForwardSelection) {
1025 auto model = std::make_unique<TextInputModel>();
1026 model->SetText("ABCDE");
1027 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1028 EXPECT_TRUE(model->MoveCursorForward());
1029 EXPECT_EQ(model->selection(), TextRange(4));
1030 EXPECT_EQ(model->composing_range(), TextRange(0));
1031 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1032}
1033
1034TEST(TextInputModel, MoveCursorForwardReverseSelection) {
1035 auto model = std::make_unique<TextInputModel>();
1036 model->SetText("ABCDE");
1037 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1038 EXPECT_TRUE(model->MoveCursorForward());
1039 EXPECT_EQ(model->selection(), TextRange(4));
1040 EXPECT_EQ(model->composing_range(), TextRange(0));
1041 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1042}
1043
1044TEST(TextInputModel, MoveCursorForwardStartComposing) {
1045 auto model = std::make_unique<TextInputModel>();
1046 model->SetText("ABCDE");
1047 model->BeginComposing();
1048 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1049 EXPECT_TRUE(model->MoveCursorForward());
1050 EXPECT_EQ(model->selection(), TextRange(2));
1051 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1052 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1053}
1054
1055TEST(TextInputModel, MoveCursorForwardStartReverseComposing) {
1056 auto model = std::make_unique<TextInputModel>();
1057 model->SetText("ABCDE");
1058 model->BeginComposing();
1059 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1060 EXPECT_TRUE(model->MoveCursorForward());
1061 EXPECT_EQ(model->selection(), TextRange(2));
1062 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1063 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1064}
1065
1066TEST(TextInputModel, MoveCursorForwardMiddleComposing) {
1067 auto model = std::make_unique<TextInputModel>();
1068 model->SetText("ABCDE");
1069 model->BeginComposing();
1070 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1071 EXPECT_TRUE(model->MoveCursorForward());
1072 EXPECT_EQ(model->selection(), TextRange(3));
1073 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1074 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1075}
1076
1077TEST(TextInputModel, MoveCursorForwardMiddleReverseComposing) {
1078 auto model = std::make_unique<TextInputModel>();
1079 model->SetText("ABCDE");
1080 model->BeginComposing();
1081 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1082 EXPECT_TRUE(model->MoveCursorForward());
1083 EXPECT_EQ(model->selection(), TextRange(3));
1084 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1085 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1086}
1087
1088TEST(TextInputModel, MoveCursorForwardEndComposing) {
1089 auto model = std::make_unique<TextInputModel>();
1090 model->SetText("ABCDE");
1091 model->BeginComposing();
1092 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1093 EXPECT_FALSE(model->MoveCursorForward());
1094 EXPECT_EQ(model->selection(), TextRange(4));
1095 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1096 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1097}
1098
1099TEST(TextInputModel, MoveCursorForwardEndReverseComposing) {
1100 auto model = std::make_unique<TextInputModel>();
1101 model->SetText("ABCDE");
1102 model->BeginComposing();
1103 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1104 EXPECT_FALSE(model->MoveCursorForward());
1105 EXPECT_EQ(model->selection(), TextRange(4));
1106 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1107 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1108}
1109
1110TEST(TextInputModel, MoveCursorBackStart) {
1111 auto model = std::make_unique<TextInputModel>();
1112 model->SetText("ABCDE");
1113 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1114 EXPECT_FALSE(model->MoveCursorBack());
1115 EXPECT_EQ(model->selection(), TextRange(0));
1116 EXPECT_EQ(model->composing_range(), TextRange(0));
1117 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1118}
1119
1120TEST(TextInputModel, MoveCursorBackMiddle) {
1121 auto model = std::make_unique<TextInputModel>();
1122 model->SetText("ABCDE");
1123 EXPECT_TRUE(model->SetSelection(TextRange(2)));
1124 EXPECT_TRUE(model->MoveCursorBack());
1125 EXPECT_EQ(model->selection(), TextRange(1));
1126 EXPECT_EQ(model->composing_range(), TextRange(0));
1127 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1128}
1129
1130TEST(TextInputModel, MoveCursorBackEnd) {
1131 auto model = std::make_unique<TextInputModel>();
1132 model->SetText("ABCDE");
1133 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1134 EXPECT_TRUE(model->MoveCursorBack());
1135 EXPECT_EQ(model->selection(), TextRange(4));
1136 EXPECT_EQ(model->composing_range(), TextRange(0));
1137 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1138}
1139
1140TEST(TextInputModel, MoveCursorBackWideCharacters) {
1141 auto model = std::make_unique<TextInputModel>();
1142 model->SetText("😄🙃🤪🧐");
1143 EXPECT_TRUE(model->SetSelection(TextRange(4)));
1144 ASSERT_TRUE(model->MoveCursorBack());
1145 EXPECT_EQ(model->selection(), TextRange(2));
1146 EXPECT_EQ(model->composing_range(), TextRange(0));
1147 EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
1148}
1149
1150TEST(TextInputModel, MoveCursorBackSelection) {
1151 auto model = std::make_unique<TextInputModel>();
1152 model->SetText("ABCDE");
1153 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1154 EXPECT_TRUE(model->MoveCursorBack());
1155 EXPECT_EQ(model->selection(), TextRange(1));
1156 EXPECT_EQ(model->composing_range(), TextRange(0));
1157 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1158}
1159
1160TEST(TextInputModel, MoveCursorBackReverseSelection) {
1161 auto model = std::make_unique<TextInputModel>();
1162 model->SetText("ABCDE");
1163 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1164 EXPECT_TRUE(model->MoveCursorBack());
1165 EXPECT_EQ(model->selection(), TextRange(1));
1166 EXPECT_EQ(model->composing_range(), TextRange(0));
1167 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1168}
1169
1170TEST(TextInputModel, MoveCursorBackStartComposing) {
1171 auto model = std::make_unique<TextInputModel>();
1172 model->SetText("ABCDE");
1173 model->BeginComposing();
1174 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1175 EXPECT_TRUE(model->SetSelection(TextRange(1)));
1176 EXPECT_FALSE(model->MoveCursorBack());
1177 EXPECT_EQ(model->selection(), TextRange(1));
1178 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1179 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1180}
1181
1182TEST(TextInputModel, MoveCursorBackStartReverseComposing) {
1183 auto model = std::make_unique<TextInputModel>();
1184 model->SetText("ABCDE");
1185 model->BeginComposing();
1186 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1187 EXPECT_TRUE(model->SetSelection(TextRange(1)));
1188 EXPECT_FALSE(model->MoveCursorBack());
1189 EXPECT_EQ(model->selection(), TextRange(1));
1190 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1191 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1192}
1193
1194TEST(TextInputModel, MoveCursorBackMiddleComposing) {
1195 auto model = std::make_unique<TextInputModel>();
1196 model->SetText("ABCDE");
1197 model->BeginComposing();
1198 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1199 EXPECT_TRUE(model->MoveCursorBack());
1200 EXPECT_EQ(model->selection(), TextRange(1));
1201 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1202 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1203}
1204
1205TEST(TextInputModel, MoveCursorBackMiddleReverseComposing) {
1206 auto model = std::make_unique<TextInputModel>();
1207 model->SetText("ABCDE");
1208 model->BeginComposing();
1209 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1210 EXPECT_TRUE(model->MoveCursorBack());
1211 EXPECT_EQ(model->selection(), TextRange(1));
1212 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1213 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1214}
1215
1216TEST(TextInputModel, MoveCursorBackEndComposing) {
1217 auto model = std::make_unique<TextInputModel>();
1218 model->SetText("ABCDE");
1219 model->BeginComposing();
1220 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1221 EXPECT_TRUE(model->MoveCursorBack());
1222 EXPECT_EQ(model->selection(), TextRange(3));
1223 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1224 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1225}
1226
1227TEST(TextInputModel, MoveCursorBackEndReverseComposing) {
1228 auto model = std::make_unique<TextInputModel>();
1229 model->SetText("ABCDE");
1230 model->BeginComposing();
1231 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1232 EXPECT_TRUE(model->MoveCursorBack());
1233 EXPECT_EQ(model->selection(), TextRange(3));
1234 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1235 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1236}
1237
1238TEST(TextInputModel, MoveCursorToBeginningStart) {
1239 auto model = std::make_unique<TextInputModel>();
1240 model->SetText("ABCDE");
1241 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1242 EXPECT_FALSE(model->MoveCursorToBeginning());
1243 EXPECT_EQ(model->selection(), TextRange(0));
1244 EXPECT_EQ(model->composing_range(), TextRange(0));
1245 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1246}
1247
1248TEST(TextInputModel, SelectToBeginningStart) {
1249 auto model = std::make_unique<TextInputModel>();
1250 model->SetText("ABCDE");
1251 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1252 EXPECT_FALSE(model->SelectToBeginning());
1253 EXPECT_EQ(model->selection(), TextRange(0));
1254 EXPECT_EQ(model->composing_range(), TextRange(0));
1255 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1256}
1257
1258TEST(TextInputModel, MoveCursorToBeginningMiddle) {
1259 auto model = std::make_unique<TextInputModel>();
1260 model->SetText("ABCDE");
1261 EXPECT_TRUE(model->SetSelection(TextRange(2)));
1262 EXPECT_TRUE(model->MoveCursorToBeginning());
1263 EXPECT_EQ(model->selection(), TextRange(0));
1264 EXPECT_EQ(model->composing_range(), TextRange(0));
1265 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1266}
1267
1268TEST(TextInputModel, SelectToBeginningMiddle) {
1269 auto model = std::make_unique<TextInputModel>();
1270 model->SetText("ABCDE");
1271 EXPECT_TRUE(model->SetSelection(TextRange(2)));
1272 EXPECT_TRUE(model->SelectToBeginning());
1273 EXPECT_EQ(model->selection(), TextRange(2, 0));
1274 EXPECT_EQ(model->composing_range(), TextRange(0));
1275 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1276}
1277
1278TEST(TextInputModel, MoveCursorToBeginningEnd) {
1279 auto model = std::make_unique<TextInputModel>();
1280 model->SetText("ABCDE");
1281 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1282 EXPECT_TRUE(model->MoveCursorToBeginning());
1283 EXPECT_EQ(model->selection(), TextRange(0));
1284 EXPECT_EQ(model->composing_range(), TextRange(0));
1285 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1286}
1287
1288TEST(TextInputModel, SelectToBeginningEnd) {
1289 auto model = std::make_unique<TextInputModel>();
1290 model->SetText("ABCDE");
1291 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1292 EXPECT_TRUE(model->SelectToBeginning());
1293 EXPECT_EQ(model->selection(), TextRange(5, 0));
1294 EXPECT_EQ(model->composing_range(), TextRange(0));
1295 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1296}
1297
1298TEST(TextInputModel, MoveCursorToBeginningSelection) {
1299 auto model = std::make_unique<TextInputModel>();
1300 model->SetText("ABCDE");
1301 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1302 EXPECT_TRUE(model->MoveCursorToBeginning());
1303 EXPECT_EQ(model->selection(), TextRange(0));
1304 EXPECT_EQ(model->composing_range(), TextRange(0));
1305 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1306}
1307
1308TEST(TextInputModel, SelectToBeginningSelection) {
1309 auto model = std::make_unique<TextInputModel>();
1310 model->SetText("ABCDE");
1311 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1312 EXPECT_TRUE(model->SelectToBeginning());
1313 EXPECT_EQ(model->selection(), TextRange(1, 0));
1314 EXPECT_EQ(model->composing_range(), TextRange(0));
1315 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1316}
1317
1318TEST(TextInputModel, MoveCursorToBeginningReverseSelection) {
1319 auto model = std::make_unique<TextInputModel>();
1320 model->SetText("ABCDE");
1321 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1322 EXPECT_TRUE(model->MoveCursorToBeginning());
1323 EXPECT_EQ(model->selection(), TextRange(0));
1324 EXPECT_EQ(model->composing_range(), TextRange(0));
1325 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1326}
1327
1328TEST(TextInputModel, SelectToBeginningReverseSelection) {
1329 auto model = std::make_unique<TextInputModel>();
1330 model->SetText("ABCDE");
1331 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1332 EXPECT_TRUE(model->SelectToBeginning());
1333 EXPECT_EQ(model->selection(), TextRange(4, 0));
1334 EXPECT_EQ(model->composing_range(), TextRange(0));
1335 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1336}
1337
1338TEST(TextInputModel, MoveCursorToBeginningStartComposing) {
1339 auto model = std::make_unique<TextInputModel>();
1340 model->SetText("ABCDE");
1341 model->BeginComposing();
1342 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1343 EXPECT_FALSE(model->MoveCursorToBeginning());
1344 EXPECT_EQ(model->selection(), TextRange(1));
1345 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1346 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1347}
1348
1349TEST(TextInputModel, SelectToBeginningStartComposing) {
1350 auto model = std::make_unique<TextInputModel>();
1351 model->SetText("ABCDE");
1352 model->BeginComposing();
1353 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1354 EXPECT_FALSE(model->SelectToBeginning());
1355 EXPECT_EQ(model->selection(), TextRange(1));
1356 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1357 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1358}
1359
1360TEST(TextInputModel, MoveCursorToBeginningStartReverseComposing) {
1361 auto model = std::make_unique<TextInputModel>();
1362 model->SetText("ABCDE");
1363 model->BeginComposing();
1364 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1365 EXPECT_FALSE(model->MoveCursorToBeginning());
1366 EXPECT_EQ(model->selection(), TextRange(1));
1367 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1368 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1369}
1370
1371TEST(TextInputModel, SelectToBeginningStartReverseComposing) {
1372 auto model = std::make_unique<TextInputModel>();
1373 model->SetText("ABCDE");
1374 model->BeginComposing();
1375 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1376 EXPECT_FALSE(model->SelectToBeginning());
1377 EXPECT_EQ(model->selection(), TextRange(1));
1378 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1379 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1380}
1381
1382TEST(TextInputModel, MoveCursorToBeginningMiddleComposing) {
1383 auto model = std::make_unique<TextInputModel>();
1384 model->SetText("ABCDE");
1385 model->BeginComposing();
1386 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1387 EXPECT_TRUE(model->MoveCursorToBeginning());
1388 EXPECT_EQ(model->selection(), TextRange(1));
1389 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1390 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1391}
1392
1393TEST(TextInputModel, SelectToBeginningMiddleComposing) {
1394 auto model = std::make_unique<TextInputModel>();
1395 model->SetText("ABCDE");
1396 model->BeginComposing();
1397 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1398 EXPECT_TRUE(model->SelectToBeginning());
1399 EXPECT_EQ(model->selection(), TextRange(2, 1));
1400 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1401 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1402}
1403
1404TEST(TextInputModel, MoveCursorToBeginningMiddleReverseComposing) {
1405 auto model = std::make_unique<TextInputModel>();
1406 model->SetText("ABCDE");
1407 model->BeginComposing();
1408 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1409 EXPECT_TRUE(model->MoveCursorToBeginning());
1410 EXPECT_EQ(model->selection(), TextRange(1));
1411 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1412 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1413}
1414
1415TEST(TextInputModel, SelectToBeginningMiddleReverseComposing) {
1416 auto model = std::make_unique<TextInputModel>();
1417 model->SetText("ABCDE");
1418 model->BeginComposing();
1419 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1420 EXPECT_TRUE(model->SelectToBeginning());
1421 EXPECT_EQ(model->selection(), TextRange(2, 1));
1422 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1423 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1424}
1425
1426TEST(TextInputModel, MoveCursorToBeginningEndComposing) {
1427 auto model = std::make_unique<TextInputModel>();
1428 model->SetText("ABCDE");
1429 model->BeginComposing();
1430 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1431 EXPECT_TRUE(model->MoveCursorToBeginning());
1432 EXPECT_EQ(model->selection(), TextRange(1));
1433 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1434 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1435}
1436
1437TEST(TextInputModel, SelectToBeginningEndComposing) {
1438 auto model = std::make_unique<TextInputModel>();
1439 model->SetText("ABCDE");
1440 model->BeginComposing();
1441 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1442 EXPECT_TRUE(model->MoveCursorToBeginning());
1443 EXPECT_EQ(model->selection(), TextRange(1));
1444 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1445 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1446}
1447
1448TEST(TextInputModel, MoveCursorToBeginningEndReverseComposing) {
1449 auto model = std::make_unique<TextInputModel>();
1450 model->SetText("ABCDE");
1451 model->BeginComposing();
1452 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1453 EXPECT_TRUE(model->MoveCursorToBeginning());
1454 EXPECT_EQ(model->selection(), TextRange(1));
1455 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1456 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1457}
1458
1459TEST(TextInputModel, SelectToBeginningEndReverseComposing) {
1460 auto model = std::make_unique<TextInputModel>();
1461 model->SetText("ABCDE");
1462 model->BeginComposing();
1463 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1464 EXPECT_TRUE(model->SelectToBeginning());
1465 EXPECT_EQ(model->selection(), TextRange(4, 1));
1466 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1467 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1468}
1469
1470TEST(TextInputModel, MoveCursorToEndStart) {
1471 auto model = std::make_unique<TextInputModel>();
1472 model->SetText("ABCDE");
1473 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1474 EXPECT_TRUE(model->MoveCursorToEnd());
1475 EXPECT_EQ(model->selection(), TextRange(5));
1476 EXPECT_EQ(model->composing_range(), TextRange(0));
1477 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1478}
1479
1480TEST(TextInputModel, SelectToEndStart) {
1481 auto model = std::make_unique<TextInputModel>();
1482 model->SetText("ABCDE");
1483 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1484 EXPECT_TRUE(model->SelectToEnd());
1485 EXPECT_EQ(model->selection(), TextRange(0, 5));
1486 EXPECT_EQ(model->composing_range(), TextRange(0));
1487 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1488}
1489
1490TEST(TextInputModel, MoveCursorToEndMiddle) {
1491 auto model = std::make_unique<TextInputModel>();
1492 model->SetText("ABCDE");
1493 EXPECT_TRUE(model->SetSelection(TextRange(2)));
1494 EXPECT_TRUE(model->MoveCursorToEnd());
1495 EXPECT_EQ(model->selection(), TextRange(5));
1496 EXPECT_EQ(model->composing_range(), TextRange(0));
1497 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1498}
1499
1500TEST(TextInputModel, SelectToEndMiddle) {
1501 auto model = std::make_unique<TextInputModel>();
1502 model->SetText("ABCDE");
1503 EXPECT_TRUE(model->SetSelection(TextRange(2)));
1504 EXPECT_TRUE(model->SelectToEnd());
1505 EXPECT_EQ(model->selection(), TextRange(2, 5));
1506 EXPECT_EQ(model->composing_range(), TextRange(0));
1507 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1508}
1509
1510TEST(TextInputModel, MoveCursorToEndEnd) {
1511 auto model = std::make_unique<TextInputModel>();
1512 model->SetText("ABCDE");
1513 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1514 EXPECT_FALSE(model->MoveCursorToEnd());
1515 EXPECT_EQ(model->selection(), TextRange(5));
1516 EXPECT_EQ(model->composing_range(), TextRange(0));
1517 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1518}
1519
1520TEST(TextInputModel, SelectToEndEnd) {
1521 auto model = std::make_unique<TextInputModel>();
1522 model->SetText("ABCDE");
1523 EXPECT_TRUE(model->SetSelection(TextRange(5)));
1524 EXPECT_FALSE(model->SelectToEnd());
1525 EXPECT_EQ(model->selection(), TextRange(5));
1526 EXPECT_EQ(model->composing_range(), TextRange(0));
1527 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1528}
1529
1530TEST(TextInputModel, MoveCursorToEndSelection) {
1531 auto model = std::make_unique<TextInputModel>();
1532 model->SetText("ABCDE");
1533 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1534 EXPECT_TRUE(model->MoveCursorToEnd());
1535 EXPECT_EQ(model->selection(), TextRange(5));
1536 EXPECT_EQ(model->composing_range(), TextRange(0));
1537 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1538}
1539
1540TEST(TextInputModel, SelectToEndSelection) {
1541 auto model = std::make_unique<TextInputModel>();
1542 model->SetText("ABCDE");
1543 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1544 EXPECT_TRUE(model->SelectToEnd());
1545 EXPECT_EQ(model->selection(), TextRange(1, 5));
1546 EXPECT_EQ(model->composing_range(), TextRange(0));
1547 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1548}
1549
1550TEST(TextInputModel, MoveCursorToEndReverseSelection) {
1551 auto model = std::make_unique<TextInputModel>();
1552 model->SetText("ABCDE");
1553 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1554 EXPECT_TRUE(model->MoveCursorToEnd());
1555 EXPECT_EQ(model->selection(), TextRange(5));
1556 EXPECT_EQ(model->composing_range(), TextRange(0));
1557 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1558}
1559
1560TEST(TextInputModel, SelectToEndReverseSelection) {
1561 auto model = std::make_unique<TextInputModel>();
1562 model->SetText("ABCDE");
1563 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1564 EXPECT_TRUE(model->SelectToEnd());
1565 EXPECT_EQ(model->selection(), TextRange(4, 5));
1566 EXPECT_EQ(model->composing_range(), TextRange(0));
1567 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1568}
1569
1570TEST(TextInputModel, MoveCursorToEndStartComposing) {
1571 auto model = std::make_unique<TextInputModel>();
1572 model->SetText("ABCDE");
1573 model->BeginComposing();
1574 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1575 EXPECT_TRUE(model->MoveCursorToEnd());
1576 EXPECT_EQ(model->selection(), TextRange(4));
1577 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1578 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1579}
1580
1581TEST(TextInputModel, SelectToEndStartComposing) {
1582 auto model = std::make_unique<TextInputModel>();
1583 model->SetText("ABCDE");
1584 model->BeginComposing();
1585 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1586 EXPECT_TRUE(model->SelectToEnd());
1587 EXPECT_EQ(model->selection(), TextRange(1, 4));
1588 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1589 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1590}
1591
1592TEST(TextInputModel, MoveCursorToEndStartReverseComposing) {
1593 auto model = std::make_unique<TextInputModel>();
1594 model->SetText("ABCDE");
1595 model->BeginComposing();
1596 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1597 EXPECT_TRUE(model->MoveCursorToEnd());
1598 EXPECT_EQ(model->selection(), TextRange(4));
1599 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1600 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1601}
1602
1603TEST(TextInputModel, SelectToEndStartReverseComposing) {
1604 auto model = std::make_unique<TextInputModel>();
1605 model->SetText("ABCDE");
1606 model->BeginComposing();
1607 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1608 EXPECT_TRUE(model->SelectToEnd());
1609 EXPECT_EQ(model->selection(), TextRange(1, 4));
1610 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1611 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1612}
1613
1614TEST(TextInputModel, MoveCursorToEndMiddleComposing) {
1615 auto model = std::make_unique<TextInputModel>();
1616 model->SetText("ABCDE");
1617 model->BeginComposing();
1618 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1619 EXPECT_TRUE(model->MoveCursorToEnd());
1620 EXPECT_EQ(model->selection(), TextRange(4));
1621 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1622 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1623}
1624
1625TEST(TextInputModel, SelectToEndMiddleComposing) {
1626 auto model = std::make_unique<TextInputModel>();
1627 model->SetText("ABCDE");
1628 model->BeginComposing();
1629 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1630 EXPECT_TRUE(model->SelectToEnd());
1631 EXPECT_EQ(model->selection(), TextRange(2, 4));
1632 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1633 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1634}
1635
1636TEST(TextInputModel, MoveCursorToEndMiddleReverseComposing) {
1637 auto model = std::make_unique<TextInputModel>();
1638 model->SetText("ABCDE");
1639 model->BeginComposing();
1640 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1641 EXPECT_TRUE(model->MoveCursorToEnd());
1642 EXPECT_EQ(model->selection(), TextRange(4));
1643 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1644 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1645}
1646
1647TEST(TextInputModel, SelectToEndMiddleReverseComposing) {
1648 auto model = std::make_unique<TextInputModel>();
1649 model->SetText("ABCDE");
1650 model->BeginComposing();
1651 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1652 EXPECT_TRUE(model->SelectToEnd());
1653 EXPECT_EQ(model->selection(), TextRange(2, 4));
1654 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1655 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1656}
1657
1658TEST(TextInputModel, MoveCursorToEndEndComposing) {
1659 auto model = std::make_unique<TextInputModel>();
1660 model->SetText("ABCDE");
1661 model->BeginComposing();
1662 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1663 EXPECT_FALSE(model->MoveCursorToEnd());
1664 EXPECT_EQ(model->selection(), TextRange(4));
1665 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1666 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1667}
1668
1669TEST(TextInputModel, SelectToEndEndComposing) {
1670 auto model = std::make_unique<TextInputModel>();
1671 model->SetText("ABCDE");
1672 model->BeginComposing();
1673 EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1674 EXPECT_FALSE(model->SelectToEnd());
1675 EXPECT_EQ(model->selection(), TextRange(4));
1676 EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1677 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1678}
1679
1680TEST(TextInputModel, MoveCursorToEndEndReverseComposing) {
1681 auto model = std::make_unique<TextInputModel>();
1682 model->SetText("ABCDE");
1683 model->BeginComposing();
1684 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1685 EXPECT_FALSE(model->MoveCursorToEnd());
1686 EXPECT_EQ(model->selection(), TextRange(4));
1687 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1688 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1689}
1690
1691TEST(TextInputModel, SelectToEndEndReverseComposing) {
1692 auto model = std::make_unique<TextInputModel>();
1693 model->SetText("ABCDE");
1694 model->BeginComposing();
1695 EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1696 EXPECT_FALSE(model->SelectToEnd());
1697 EXPECT_EQ(model->selection(), TextRange(4));
1698 EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1699 EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1700}
1701
1702TEST(TextInputModel, GetCursorOffset) {
1703 auto model = std::make_unique<TextInputModel>();
1704 // These characters take 1, 2, 3 and 4 bytes in UTF-8.
1705 model->SetText("$¢€𐍈");
1706 EXPECT_TRUE(model->SetSelection(TextRange(0)));
1707 EXPECT_EQ(model->GetCursorOffset(), 0);
1708 EXPECT_TRUE(model->MoveCursorForward());
1709 EXPECT_EQ(model->GetCursorOffset(), 1);
1710 EXPECT_TRUE(model->MoveCursorForward());
1711 EXPECT_EQ(model->GetCursorOffset(), 3);
1712 EXPECT_TRUE(model->MoveCursorForward());
1713 EXPECT_EQ(model->GetCursorOffset(), 6);
1714 EXPECT_TRUE(model->MoveCursorForward());
1715 EXPECT_EQ(model->GetCursorOffset(), 10);
1716}
1717
1718TEST(TextInputModel, GetCursorOffsetSelection) {
1719 auto model = std::make_unique<TextInputModel>();
1720 model->SetText("ABCDE");
1721 EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1722 EXPECT_EQ(model->GetCursorOffset(), 4);
1723}
1724
1725TEST(TextInputModel, GetCursorOffsetReverseSelection) {
1726 auto model = std::make_unique<TextInputModel>();
1727 model->SetText("ABCDE");
1728 EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1729 EXPECT_EQ(model->GetCursorOffset(), 1);
1730}
1731
1732} // namespace flutter
TEST(FrameTimingsRecorderTest, RecordVsync)
SkRange< size_t > TextRange
Definition: TextStyle.h:337
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678