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/cpp/text_input_model.h"
6 
7 #include <limits>
8 #include <map>
9 #include <vector>
10 
11 #include "gtest/gtest.h"
12 
13 namespace flutter {
14 
15 TEST(TextInputModel, SetText) {
16  auto model = std::make_unique<TextInputModel>();
17  model->SetText("ABCDE");
18  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
19 }
20 
21 TEST(TextInputModel, SetTextWideCharacters) {
22  auto model = std::make_unique<TextInputModel>();
23  model->SetText("😄🙃🤪🧐");
24  EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
25 }
26 
27 TEST(TextInputModel, SetTextEmpty) {
28  auto model = std::make_unique<TextInputModel>();
29  model->SetText("");
30  EXPECT_STREQ(model->GetText().c_str(), "");
31 }
32 
33 TEST(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 
41 TEST(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 
50 TEST(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 
59 TEST(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 
70 TEST(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 
79 TEST(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 
90 TEST(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 
99 TEST(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 
110 TEST(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 
119 TEST(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 
130 TEST(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 
139 TEST(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 
150 TEST(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 
158 TEST(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 
170 TEST(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 
180 TEST(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 
190 TEST(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 
200 TEST(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 
210 TEST(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 
220 TEST(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.
230 TEST(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.
255 TEST(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.
280 TEST(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.
336 TEST(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 
395 TEST(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 
406 TEST(TextInputModel, AddCodePoint) {
407  auto model = std::make_unique<TextInputModel>();
408  model->AddCodePoint('A');
409  model->AddCodePoint('B');
410  model->AddCodePoint(0x1f604);
411  model->AddCodePoint('D');
412  model->AddCodePoint('E');
413  EXPECT_EQ(model->selection(), TextRange(6));
414  EXPECT_EQ(model->composing_range(), TextRange(0));
415  EXPECT_STREQ(model->GetText().c_str(), "AB😄DE");
416 }
417 
418 TEST(TextInputModel, AddCodePointSelection) {
419  auto model = std::make_unique<TextInputModel>();
420  model->SetText("ABCDE");
421  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
422  model->AddCodePoint('x');
423  EXPECT_EQ(model->selection(), TextRange(2));
424  EXPECT_EQ(model->composing_range(), TextRange(0));
425  EXPECT_STREQ(model->GetText().c_str(), "AxE");
426 }
427 
428 TEST(TextInputModel, AddCodePointReverseSelection) {
429  auto model = std::make_unique<TextInputModel>();
430  model->SetText("ABCDE");
431  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
432  model->AddCodePoint('x');
433  EXPECT_EQ(model->selection(), TextRange(2));
434  EXPECT_EQ(model->composing_range(), TextRange(0));
435  EXPECT_STREQ(model->GetText().c_str(), "AxE");
436 }
437 
438 TEST(TextInputModel, AddCodePointSelectionWideCharacter) {
439  auto model = std::make_unique<TextInputModel>();
440  model->SetText("ABCDE");
441  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
442  model->AddCodePoint(0x1f604);
443  EXPECT_EQ(model->selection(), TextRange(3));
444  EXPECT_EQ(model->composing_range(), TextRange(0));
445  EXPECT_STREQ(model->GetText().c_str(), "A😄E");
446 }
447 
448 TEST(TextInputModel, AddCodePointReverseSelectionWideCharacter) {
449  auto model = std::make_unique<TextInputModel>();
450  model->SetText("ABCDE");
451  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
452  model->AddCodePoint(0x1f604);
453  EXPECT_EQ(model->selection(), TextRange(3));
454  EXPECT_EQ(model->composing_range(), TextRange(0));
455  EXPECT_STREQ(model->GetText().c_str(), "A😄E");
456 }
457 
458 TEST(TextInputModel, AddText) {
459  auto model = std::make_unique<TextInputModel>();
460  model->AddText(u"ABCDE");
461  model->AddText("😄");
462  model->AddText("FGHIJ");
463  EXPECT_EQ(model->selection(), TextRange(12));
464  EXPECT_EQ(model->composing_range(), TextRange(0));
465  EXPECT_STREQ(model->GetText().c_str(), "ABCDE😄FGHIJ");
466 }
467 
468 TEST(TextInputModel, AddTextSelection) {
469  auto model = std::make_unique<TextInputModel>();
470  model->SetText("ABCDE");
471  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
472  model->AddText("xy");
473  EXPECT_EQ(model->selection(), TextRange(3));
474  EXPECT_EQ(model->composing_range(), TextRange(0));
475  EXPECT_STREQ(model->GetText().c_str(), "AxyE");
476 }
477 
478 TEST(TextInputModel, AddTextReverseSelection) {
479  auto model = std::make_unique<TextInputModel>();
480  model->SetText("ABCDE");
481  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
482  model->AddText("xy");
483  EXPECT_EQ(model->selection(), TextRange(3));
484  EXPECT_EQ(model->composing_range(), TextRange(0));
485  EXPECT_STREQ(model->GetText().c_str(), "AxyE");
486 }
487 
488 TEST(TextInputModel, AddTextSelectionWideCharacter) {
489  auto model = std::make_unique<TextInputModel>();
490  model->SetText("ABCDE");
491  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
492  model->AddText(u"😄🙃");
493  EXPECT_EQ(model->selection(), TextRange(5));
494  EXPECT_EQ(model->composing_range(), TextRange(0));
495  EXPECT_STREQ(model->GetText().c_str(), "A😄🙃E");
496 }
497 
498 TEST(TextInputModel, AddTextReverseSelectionWideCharacter) {
499  auto model = std::make_unique<TextInputModel>();
500  model->SetText("ABCDE");
501  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
502  model->AddText(u"😄🙃");
503  EXPECT_EQ(model->selection(), TextRange(5));
504  EXPECT_EQ(model->composing_range(), TextRange(0));
505  EXPECT_STREQ(model->GetText().c_str(), "A😄🙃E");
506 }
507 
508 TEST(TextInputModel, DeleteStart) {
509  auto model = std::make_unique<TextInputModel>();
510  model->SetText("ABCDE");
511  EXPECT_TRUE(model->SetSelection(TextRange(0)));
512  ASSERT_TRUE(model->Delete());
513  EXPECT_EQ(model->selection(), TextRange(0));
514  EXPECT_EQ(model->composing_range(), TextRange(0));
515  EXPECT_STREQ(model->GetText().c_str(), "BCDE");
516 }
517 
518 TEST(TextInputModel, DeleteMiddle) {
519  auto model = std::make_unique<TextInputModel>();
520  model->SetText("ABCDE");
521  EXPECT_TRUE(model->SetSelection(TextRange(2)));
522  ASSERT_TRUE(model->Delete());
523  EXPECT_EQ(model->selection(), TextRange(2));
524  EXPECT_EQ(model->composing_range(), TextRange(0));
525  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
526 }
527 
528 TEST(TextInputModel, DeleteEnd) {
529  auto model = std::make_unique<TextInputModel>();
530  model->SetText("ABCDE");
531  EXPECT_TRUE(model->SetSelection(TextRange(5)));
532  ASSERT_FALSE(model->Delete());
533  EXPECT_EQ(model->selection(), TextRange(5));
534  EXPECT_EQ(model->composing_range(), TextRange(0));
535  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
536 }
537 
538 TEST(TextInputModel, DeleteWideCharacters) {
539  auto model = std::make_unique<TextInputModel>();
540  model->SetText("😄🙃🤪🧐");
541  EXPECT_TRUE(model->SetSelection(TextRange(4)));
542  ASSERT_TRUE(model->Delete());
543  EXPECT_EQ(model->selection(), TextRange(4));
544  EXPECT_EQ(model->composing_range(), TextRange(0));
545  EXPECT_STREQ(model->GetText().c_str(), "😄🙃🧐");
546 }
547 
548 TEST(TextInputModel, DeleteSelection) {
549  auto model = std::make_unique<TextInputModel>();
550  model->SetText("ABCDE");
551  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
552  ASSERT_TRUE(model->Delete());
553  EXPECT_EQ(model->selection(), TextRange(1));
554  EXPECT_EQ(model->composing_range(), TextRange(0));
555  EXPECT_STREQ(model->GetText().c_str(), "AE");
556 }
557 
558 TEST(TextInputModel, DeleteReverseSelection) {
559  auto model = std::make_unique<TextInputModel>();
560  model->SetText("ABCDE");
561  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
562  ASSERT_TRUE(model->Delete());
563  EXPECT_EQ(model->selection(), TextRange(1));
564  EXPECT_EQ(model->composing_range(), TextRange(0));
565  EXPECT_STREQ(model->GetText().c_str(), "AE");
566 }
567 
568 TEST(TextInputModel, DeleteStartComposing) {
569  auto model = std::make_unique<TextInputModel>();
570  model->SetText("ABCDE");
571  model->BeginComposing();
572  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
573  EXPECT_EQ(model->selection(), TextRange(1));
574  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
575  ASSERT_TRUE(model->Delete());
576  EXPECT_EQ(model->selection(), TextRange(1));
577  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
578  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
579 }
580 
581 TEST(TextInputModel, DeleteStartReverseComposing) {
582  auto model = std::make_unique<TextInputModel>();
583  model->SetText("ABCDE");
584  model->BeginComposing();
585  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
586  EXPECT_EQ(model->selection(), TextRange(1));
587  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
588  ASSERT_TRUE(model->Delete());
589  EXPECT_EQ(model->selection(), TextRange(1));
590  EXPECT_EQ(model->composing_range(), TextRange(3, 1));
591  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
592 }
593 
594 TEST(TextInputModel, DeleteMiddleComposing) {
595  auto model = std::make_unique<TextInputModel>();
596  model->SetText("ABCDE");
597  model->BeginComposing();
598  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
599  ASSERT_TRUE(model->Delete());
600  EXPECT_EQ(model->selection(), TextRange(2));
601  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
602  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
603 }
604 
605 TEST(TextInputModel, DeleteMiddleReverseComposing) {
606  auto model = std::make_unique<TextInputModel>();
607  model->SetText("ABCDE");
608  model->BeginComposing();
609  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
610  ASSERT_TRUE(model->Delete());
611  EXPECT_EQ(model->selection(), TextRange(2));
612  EXPECT_EQ(model->composing_range(), TextRange(3, 1));
613  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
614 }
615 
616 TEST(TextInputModel, DeleteEndComposing) {
617  auto model = std::make_unique<TextInputModel>();
618  model->SetText("ABCDE");
619  model->BeginComposing();
620  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
621  ASSERT_FALSE(model->Delete());
622  EXPECT_EQ(model->selection(), TextRange(4));
623  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
624  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
625 }
626 
627 TEST(TextInputModel, DeleteEndReverseComposing) {
628  auto model = std::make_unique<TextInputModel>();
629  model->SetText("ABCDE");
630  model->BeginComposing();
631  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
632  ASSERT_FALSE(model->Delete());
633  EXPECT_EQ(model->selection(), TextRange(4));
634  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
635  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
636 }
637 
638 TEST(TextInputModel, DeleteSurroundingAtCursor) {
639  auto model = std::make_unique<TextInputModel>();
640  model->SetText("ABCDE");
641  EXPECT_TRUE(model->SetSelection(TextRange(2)));
642  EXPECT_TRUE(model->DeleteSurrounding(0, 1));
643  EXPECT_EQ(model->selection(), TextRange(2));
644  EXPECT_EQ(model->composing_range(), TextRange(0));
645  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
646 }
647 
648 TEST(TextInputModel, DeleteSurroundingAtCursorComposing) {
649  auto model = std::make_unique<TextInputModel>();
650  model->SetText("ABCDE");
651  model->BeginComposing();
652  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
653  EXPECT_TRUE(model->DeleteSurrounding(0, 1));
654  EXPECT_EQ(model->selection(), TextRange(2));
655  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
656  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
657 }
658 
659 TEST(TextInputModel, DeleteSurroundingAtCursorAll) {
660  auto model = std::make_unique<TextInputModel>();
661  model->SetText("ABCDE");
662  EXPECT_TRUE(model->SetSelection(TextRange(2)));
663  EXPECT_TRUE(model->DeleteSurrounding(0, 3));
664  EXPECT_EQ(model->selection(), TextRange(2));
665  EXPECT_EQ(model->composing_range(), TextRange(0));
666  EXPECT_STREQ(model->GetText().c_str(), "AB");
667 }
668 
669 TEST(TextInputModel, DeleteSurroundingAtCursorAllComposing) {
670  auto model = std::make_unique<TextInputModel>();
671  model->SetText("ABCDE");
672  model->BeginComposing();
673  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
674  EXPECT_TRUE(model->DeleteSurrounding(0, 2));
675  EXPECT_EQ(model->selection(), TextRange(2));
676  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
677  EXPECT_STREQ(model->GetText().c_str(), "ABE");
678 }
679 
680 TEST(TextInputModel, DeleteSurroundingAtCursorGreedy) {
681  auto model = std::make_unique<TextInputModel>();
682  model->SetText("ABCDE");
683  EXPECT_TRUE(model->SetSelection(TextRange(2)));
684  EXPECT_TRUE(model->DeleteSurrounding(0, 4));
685  EXPECT_EQ(model->selection(), TextRange(2));
686  EXPECT_EQ(model->composing_range(), TextRange(0));
687  EXPECT_STREQ(model->GetText().c_str(), "AB");
688 }
689 
690 TEST(TextInputModel, DeleteSurroundingAtCursorGreedyComposing) {
691  auto model = std::make_unique<TextInputModel>();
692  model->SetText("ABCDE");
693  model->BeginComposing();
694  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
695  EXPECT_TRUE(model->DeleteSurrounding(0, 4));
696  EXPECT_EQ(model->selection(), TextRange(2));
697  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
698  EXPECT_STREQ(model->GetText().c_str(), "ABE");
699 }
700 
701 TEST(TextInputModel, DeleteSurroundingBeforeCursor) {
702  auto model = std::make_unique<TextInputModel>();
703  model->SetText("ABCDE");
704  EXPECT_TRUE(model->SetSelection(TextRange(2)));
705  EXPECT_TRUE(model->DeleteSurrounding(-1, 1));
706  EXPECT_EQ(model->selection(), TextRange(1));
707  EXPECT_EQ(model->composing_range(), TextRange(0));
708  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
709 }
710 
711 TEST(TextInputModel, DeleteSurroundingBeforeCursorComposing) {
712  auto model = std::make_unique<TextInputModel>();
713  model->SetText("ABCDE");
714  model->BeginComposing();
715  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
716  EXPECT_TRUE(model->DeleteSurrounding(-1, 1));
717  EXPECT_EQ(model->selection(), TextRange(2));
718  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
719  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
720 }
721 
722 TEST(TextInputModel, DeleteSurroundingBeforeCursorAll) {
723  auto model = std::make_unique<TextInputModel>();
724  model->SetText("ABCDE");
725  EXPECT_TRUE(model->SetSelection(TextRange(2)));
726  EXPECT_TRUE(model->DeleteSurrounding(-2, 2));
727  EXPECT_EQ(model->selection(), TextRange(0));
728  EXPECT_EQ(model->composing_range(), TextRange(0));
729  EXPECT_STREQ(model->GetText().c_str(), "CDE");
730 }
731 
732 TEST(TextInputModel, DeleteSurroundingBeforeCursorAllComposing) {
733  auto model = std::make_unique<TextInputModel>();
734  model->SetText("ABCDE");
735  model->BeginComposing();
736  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
737  EXPECT_TRUE(model->DeleteSurrounding(-2, 2));
738  EXPECT_EQ(model->selection(), TextRange(1));
739  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
740  EXPECT_STREQ(model->GetText().c_str(), "ADE");
741 }
742 
743 TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedy) {
744  auto model = std::make_unique<TextInputModel>();
745  model->SetText("ABCDE");
746  EXPECT_TRUE(model->SetSelection(TextRange(2)));
747  EXPECT_TRUE(model->DeleteSurrounding(-3, 3));
748  EXPECT_EQ(model->selection(), TextRange(0));
749  EXPECT_EQ(model->composing_range(), TextRange(0));
750  EXPECT_STREQ(model->GetText().c_str(), "CDE");
751 }
752 
753 TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedyComposing) {
754  auto model = std::make_unique<TextInputModel>();
755  model->SetText("ABCDE");
756  model->BeginComposing();
757  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 2));
758  EXPECT_TRUE(model->DeleteSurrounding(-3, 3));
759  EXPECT_EQ(model->selection(), TextRange(1));
760  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
761  EXPECT_STREQ(model->GetText().c_str(), "ADE");
762 }
763 
764 TEST(TextInputModel, DeleteSurroundingAfterCursor) {
765  auto model = std::make_unique<TextInputModel>();
766  model->SetText("ABCDE");
767  EXPECT_TRUE(model->SetSelection(TextRange(2)));
768  EXPECT_TRUE(model->DeleteSurrounding(1, 1));
769  EXPECT_EQ(model->selection(), TextRange(2));
770  EXPECT_EQ(model->composing_range(), TextRange(0));
771  EXPECT_STREQ(model->GetText().c_str(), "ABCE");
772 }
773 
774 TEST(TextInputModel, DeleteSurroundingAfterCursorComposing) {
775  auto model = std::make_unique<TextInputModel>();
776  model->SetText("ABCDE");
777  model->BeginComposing();
778  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
779  EXPECT_TRUE(model->DeleteSurrounding(1, 1));
780  EXPECT_EQ(model->selection(), TextRange(1));
781  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
782  EXPECT_STREQ(model->GetText().c_str(), "ABDE");
783 }
784 
785 TEST(TextInputModel, DeleteSurroundingAfterCursorAll) {
786  auto model = std::make_unique<TextInputModel>();
787  model->SetText("ABCDE");
788  EXPECT_TRUE(model->SetSelection(TextRange(2)));
789  EXPECT_TRUE(model->DeleteSurrounding(1, 2));
790  EXPECT_EQ(model->selection(), TextRange(2));
791  EXPECT_EQ(model->composing_range(), TextRange(0));
792  EXPECT_STREQ(model->GetText().c_str(), "ABC");
793 }
794 
795 TEST(TextInputModel, DeleteSurroundingAfterCursorAllComposing) {
796  auto model = std::make_unique<TextInputModel>();
797  model->SetText("ABCDE");
798  model->BeginComposing();
799  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
800  EXPECT_TRUE(model->DeleteSurrounding(1, 2));
801  EXPECT_EQ(model->selection(), TextRange(1));
802  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
803  EXPECT_STREQ(model->GetText().c_str(), "ABE");
804 }
805 
806 TEST(TextInputModel, DeleteSurroundingAfterCursorGreedy) {
807  auto model = std::make_unique<TextInputModel>();
808  model->SetText("ABCDE");
809  EXPECT_TRUE(model->SetSelection(TextRange(2)));
810  EXPECT_TRUE(model->DeleteSurrounding(1, 3));
811  EXPECT_EQ(model->selection(), TextRange(2));
812  EXPECT_EQ(model->composing_range(), TextRange(0));
813  EXPECT_STREQ(model->GetText().c_str(), "ABC");
814 }
815 
816 TEST(TextInputModel, DeleteSurroundingAfterCursorGreedyComposing) {
817  auto model = std::make_unique<TextInputModel>();
818  model->SetText("ABCDE");
819  model->BeginComposing();
820  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
821  EXPECT_TRUE(model->DeleteSurrounding(1, 3));
822  EXPECT_EQ(model->selection(), TextRange(1));
823  EXPECT_EQ(model->composing_range(), TextRange(1, 2));
824  EXPECT_STREQ(model->GetText().c_str(), "ABE");
825 }
826 
827 TEST(TextInputModel, DeleteSurroundingSelection) {
828  auto model = std::make_unique<TextInputModel>();
829  model->SetText("ABCDE");
830  EXPECT_TRUE(model->SetSelection(TextRange(2, 3)));
831  EXPECT_TRUE(model->DeleteSurrounding(0, 1));
832  EXPECT_EQ(model->selection(), TextRange(3));
833  EXPECT_EQ(model->composing_range(), TextRange(0));
834  EXPECT_STREQ(model->GetText().c_str(), "ABCE");
835 }
836 
837 TEST(TextInputModel, DeleteSurroundingReverseSelection) {
838  auto model = std::make_unique<TextInputModel>();
839  model->SetText("ABCDE");
840  EXPECT_TRUE(model->SetSelection(TextRange(4, 3)));
841  EXPECT_TRUE(model->DeleteSurrounding(0, 1));
842  EXPECT_EQ(model->selection(), TextRange(3));
843  EXPECT_EQ(model->composing_range(), TextRange(0));
844  EXPECT_STREQ(model->GetText().c_str(), "ABCE");
845 }
846 
847 TEST(TextInputModel, BackspaceStart) {
848  auto model = std::make_unique<TextInputModel>();
849  model->SetText("ABCDE");
850  EXPECT_TRUE(model->SetSelection(TextRange(0)));
851  ASSERT_FALSE(model->Backspace());
852  EXPECT_EQ(model->selection(), TextRange(0));
853  EXPECT_EQ(model->composing_range(), TextRange(0));
854  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
855 }
856 
857 TEST(TextInputModel, BackspaceMiddle) {
858  auto model = std::make_unique<TextInputModel>();
859  model->SetText("ABCDE");
860  EXPECT_TRUE(model->SetSelection(TextRange(2)));
861  ASSERT_TRUE(model->Backspace());
862  EXPECT_EQ(model->selection(), TextRange(1));
863  EXPECT_EQ(model->composing_range(), TextRange(0));
864  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
865 }
866 
867 TEST(TextInputModel, BackspaceEnd) {
868  auto model = std::make_unique<TextInputModel>();
869  model->SetText("ABCDE");
870  EXPECT_TRUE(model->SetSelection(TextRange(5)));
871  ASSERT_TRUE(model->Backspace());
872  EXPECT_EQ(model->selection(), TextRange(4));
873  EXPECT_EQ(model->composing_range(), TextRange(0));
874  EXPECT_STREQ(model->GetText().c_str(), "ABCD");
875 }
876 
877 TEST(TextInputModel, BackspaceWideCharacters) {
878  auto model = std::make_unique<TextInputModel>();
879  model->SetText("😄🙃🤪🧐");
880  EXPECT_TRUE(model->SetSelection(TextRange(4)));
881  ASSERT_TRUE(model->Backspace());
882  EXPECT_EQ(model->selection(), TextRange(2));
883  EXPECT_EQ(model->composing_range(), TextRange(0));
884  EXPECT_STREQ(model->GetText().c_str(), "😄🤪🧐");
885 }
886 
887 TEST(TextInputModel, BackspaceSelection) {
888  auto model = std::make_unique<TextInputModel>();
889  model->SetText("ABCDE");
890  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
891  ASSERT_TRUE(model->Delete());
892  EXPECT_EQ(model->selection(), TextRange(1));
893  EXPECT_EQ(model->composing_range(), TextRange(0));
894  EXPECT_STREQ(model->GetText().c_str(), "AE");
895 }
896 
897 TEST(TextInputModel, BackspaceReverseSelection) {
898  auto model = std::make_unique<TextInputModel>();
899  model->SetText("ABCDE");
900  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
901  ASSERT_TRUE(model->Delete());
902  EXPECT_EQ(model->selection(), TextRange(1));
903  EXPECT_EQ(model->composing_range(), TextRange(0));
904  EXPECT_STREQ(model->GetText().c_str(), "AE");
905 }
906 
907 TEST(TextInputModel, BackspaceStartComposing) {
908  auto model = std::make_unique<TextInputModel>();
909  model->SetText("ABCDE");
910  model->BeginComposing();
911  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
912  ASSERT_FALSE(model->Backspace());
913  EXPECT_EQ(model->selection(), TextRange(1));
914  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
915  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
916 }
917 
918 TEST(TextInputModel, BackspaceStartReverseComposing) {
919  auto model = std::make_unique<TextInputModel>();
920  model->SetText("ABCDE");
921  model->BeginComposing();
922  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
923  ASSERT_FALSE(model->Backspace());
924  EXPECT_EQ(model->selection(), TextRange(1));
925  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
926  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
927 }
928 
929 TEST(TextInputModel, BackspaceMiddleComposing) {
930  auto model = std::make_unique<TextInputModel>();
931  model->SetText("ABCDE");
932  model->BeginComposing();
933  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
934  ASSERT_TRUE(model->Backspace());
935  EXPECT_EQ(model->selection(), TextRange(1));
936  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
937  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
938 }
939 
940 TEST(TextInputModel, BackspaceMiddleReverseComposing) {
941  auto model = std::make_unique<TextInputModel>();
942  model->SetText("ABCDE");
943  model->BeginComposing();
944  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
945  ASSERT_TRUE(model->Backspace());
946  EXPECT_EQ(model->selection(), TextRange(1));
947  EXPECT_EQ(model->composing_range(), TextRange(3, 1));
948  EXPECT_STREQ(model->GetText().c_str(), "ACDE");
949 }
950 
951 TEST(TextInputModel, BackspaceEndComposing) {
952  auto model = std::make_unique<TextInputModel>();
953  model->SetText("ABCDE");
954  model->BeginComposing();
955  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
956  ASSERT_TRUE(model->Backspace());
957  EXPECT_EQ(model->selection(), TextRange(3));
958  EXPECT_EQ(model->composing_range(), TextRange(1, 3));
959  EXPECT_STREQ(model->GetText().c_str(), "ABCE");
960 }
961 
962 TEST(TextInputModel, BackspaceEndReverseComposing) {
963  auto model = std::make_unique<TextInputModel>();
964  model->SetText("ABCDE");
965  model->BeginComposing();
966  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
967  ASSERT_TRUE(model->Backspace());
968  EXPECT_EQ(model->selection(), TextRange(3));
969  EXPECT_EQ(model->composing_range(), TextRange(3, 1));
970  EXPECT_STREQ(model->GetText().c_str(), "ABCE");
971 }
972 
973 TEST(TextInputModel, MoveCursorForwardStart) {
974  auto model = std::make_unique<TextInputModel>();
975  model->SetText("ABCDE");
976  EXPECT_TRUE(model->SetSelection(TextRange(0)));
977  EXPECT_TRUE(model->MoveCursorForward());
978  EXPECT_EQ(model->selection(), TextRange(1));
979  EXPECT_EQ(model->composing_range(), TextRange(0));
980  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
981 }
982 
983 TEST(TextInputModel, MoveCursorForwardMiddle) {
984  auto model = std::make_unique<TextInputModel>();
985  model->SetText("ABCDE");
986  EXPECT_TRUE(model->SetSelection(TextRange(2)));
987  EXPECT_TRUE(model->MoveCursorForward());
988  EXPECT_EQ(model->selection(), TextRange(3));
989  EXPECT_EQ(model->composing_range(), TextRange(0));
990  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
991 }
992 
993 TEST(TextInputModel, MoveCursorForwardEnd) {
994  auto model = std::make_unique<TextInputModel>();
995  model->SetText("ABCDE");
996  EXPECT_TRUE(model->SetSelection(TextRange(5)));
997  EXPECT_FALSE(model->MoveCursorForward());
998  EXPECT_EQ(model->selection(), TextRange(5));
999  EXPECT_EQ(model->composing_range(), TextRange(0));
1000  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1001 }
1002 
1003 TEST(TextInputModel, MoveCursorForwardWideCharacters) {
1004  auto model = std::make_unique<TextInputModel>();
1005  model->SetText("😄🙃🤪🧐");
1006  EXPECT_TRUE(model->SetSelection(TextRange(4)));
1007  ASSERT_TRUE(model->MoveCursorForward());
1008  EXPECT_EQ(model->selection(), TextRange(6));
1009  EXPECT_EQ(model->composing_range(), TextRange(0));
1010  EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
1011 }
1012 
1013 TEST(TextInputModel, MoveCursorForwardSelection) {
1014  auto model = std::make_unique<TextInputModel>();
1015  model->SetText("ABCDE");
1016  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1017  EXPECT_TRUE(model->MoveCursorForward());
1018  EXPECT_EQ(model->selection(), TextRange(4));
1019  EXPECT_EQ(model->composing_range(), TextRange(0));
1020  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1021 }
1022 
1023 TEST(TextInputModel, MoveCursorForwardReverseSelection) {
1024  auto model = std::make_unique<TextInputModel>();
1025  model->SetText("ABCDE");
1026  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1027  EXPECT_TRUE(model->MoveCursorForward());
1028  EXPECT_EQ(model->selection(), TextRange(4));
1029  EXPECT_EQ(model->composing_range(), TextRange(0));
1030  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1031 }
1032 
1033 TEST(TextInputModel, MoveCursorForwardStartComposing) {
1034  auto model = std::make_unique<TextInputModel>();
1035  model->SetText("ABCDE");
1036  model->BeginComposing();
1037  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1038  EXPECT_TRUE(model->MoveCursorForward());
1039  EXPECT_EQ(model->selection(), TextRange(2));
1040  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1041  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1042 }
1043 
1044 TEST(TextInputModel, MoveCursorForwardStartReverseComposing) {
1045  auto model = std::make_unique<TextInputModel>();
1046  model->SetText("ABCDE");
1047  model->BeginComposing();
1048  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1049  EXPECT_TRUE(model->MoveCursorForward());
1050  EXPECT_EQ(model->selection(), TextRange(2));
1051  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1052  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1053 }
1054 
1055 TEST(TextInputModel, MoveCursorForwardMiddleComposing) {
1056  auto model = std::make_unique<TextInputModel>();
1057  model->SetText("ABCDE");
1058  model->BeginComposing();
1059  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1060  EXPECT_TRUE(model->MoveCursorForward());
1061  EXPECT_EQ(model->selection(), TextRange(3));
1062  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1063  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1064 }
1065 
1066 TEST(TextInputModel, MoveCursorForwardMiddleReverseComposing) {
1067  auto model = std::make_unique<TextInputModel>();
1068  model->SetText("ABCDE");
1069  model->BeginComposing();
1070  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1071  EXPECT_TRUE(model->MoveCursorForward());
1072  EXPECT_EQ(model->selection(), TextRange(3));
1073  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1074  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1075 }
1076 
1077 TEST(TextInputModel, MoveCursorForwardEndComposing) {
1078  auto model = std::make_unique<TextInputModel>();
1079  model->SetText("ABCDE");
1080  model->BeginComposing();
1081  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1082  EXPECT_FALSE(model->MoveCursorForward());
1083  EXPECT_EQ(model->selection(), TextRange(4));
1084  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1085  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1086 }
1087 
1088 TEST(TextInputModel, MoveCursorForwardEndReverseComposing) {
1089  auto model = std::make_unique<TextInputModel>();
1090  model->SetText("ABCDE");
1091  model->BeginComposing();
1092  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1093  EXPECT_FALSE(model->MoveCursorForward());
1094  EXPECT_EQ(model->selection(), TextRange(4));
1095  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1096  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1097 }
1098 
1099 TEST(TextInputModel, MoveCursorBackStart) {
1100  auto model = std::make_unique<TextInputModel>();
1101  model->SetText("ABCDE");
1102  EXPECT_TRUE(model->SetSelection(TextRange(0)));
1103  EXPECT_FALSE(model->MoveCursorBack());
1104  EXPECT_EQ(model->selection(), TextRange(0));
1105  EXPECT_EQ(model->composing_range(), TextRange(0));
1106  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1107 }
1108 
1109 TEST(TextInputModel, MoveCursorBackMiddle) {
1110  auto model = std::make_unique<TextInputModel>();
1111  model->SetText("ABCDE");
1112  EXPECT_TRUE(model->SetSelection(TextRange(2)));
1113  EXPECT_TRUE(model->MoveCursorBack());
1114  EXPECT_EQ(model->selection(), TextRange(1));
1115  EXPECT_EQ(model->composing_range(), TextRange(0));
1116  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1117 }
1118 
1119 TEST(TextInputModel, MoveCursorBackEnd) {
1120  auto model = std::make_unique<TextInputModel>();
1121  model->SetText("ABCDE");
1122  EXPECT_TRUE(model->SetSelection(TextRange(5)));
1123  EXPECT_TRUE(model->MoveCursorBack());
1124  EXPECT_EQ(model->selection(), TextRange(4));
1125  EXPECT_EQ(model->composing_range(), TextRange(0));
1126  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1127 }
1128 
1129 TEST(TextInputModel, MoveCursorBackWideCharacters) {
1130  auto model = std::make_unique<TextInputModel>();
1131  model->SetText("😄🙃🤪🧐");
1132  EXPECT_TRUE(model->SetSelection(TextRange(4)));
1133  ASSERT_TRUE(model->MoveCursorBack());
1134  EXPECT_EQ(model->selection(), TextRange(2));
1135  EXPECT_EQ(model->composing_range(), TextRange(0));
1136  EXPECT_STREQ(model->GetText().c_str(), "😄🙃🤪🧐");
1137 }
1138 
1139 TEST(TextInputModel, MoveCursorBackSelection) {
1140  auto model = std::make_unique<TextInputModel>();
1141  model->SetText("ABCDE");
1142  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1143  EXPECT_TRUE(model->MoveCursorBack());
1144  EXPECT_EQ(model->selection(), TextRange(1));
1145  EXPECT_EQ(model->composing_range(), TextRange(0));
1146  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1147 }
1148 
1149 TEST(TextInputModel, MoveCursorBackReverseSelection) {
1150  auto model = std::make_unique<TextInputModel>();
1151  model->SetText("ABCDE");
1152  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1153  EXPECT_TRUE(model->MoveCursorBack());
1154  EXPECT_EQ(model->selection(), TextRange(1));
1155  EXPECT_EQ(model->composing_range(), TextRange(0));
1156  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1157 }
1158 
1159 TEST(TextInputModel, MoveCursorBackStartComposing) {
1160  auto model = std::make_unique<TextInputModel>();
1161  model->SetText("ABCDE");
1162  model->BeginComposing();
1163  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1164  EXPECT_TRUE(model->SetSelection(TextRange(1)));
1165  EXPECT_FALSE(model->MoveCursorBack());
1166  EXPECT_EQ(model->selection(), TextRange(1));
1167  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1168  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1169 }
1170 
1171 TEST(TextInputModel, MoveCursorBackStartReverseComposing) {
1172  auto model = std::make_unique<TextInputModel>();
1173  model->SetText("ABCDE");
1174  model->BeginComposing();
1175  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1176  EXPECT_TRUE(model->SetSelection(TextRange(1)));
1177  EXPECT_FALSE(model->MoveCursorBack());
1178  EXPECT_EQ(model->selection(), TextRange(1));
1179  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1180  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1181 }
1182 
1183 TEST(TextInputModel, MoveCursorBackMiddleComposing) {
1184  auto model = std::make_unique<TextInputModel>();
1185  model->SetText("ABCDE");
1186  model->BeginComposing();
1187  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1188  EXPECT_TRUE(model->MoveCursorBack());
1189  EXPECT_EQ(model->selection(), TextRange(1));
1190  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1191  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1192 }
1193 
1194 TEST(TextInputModel, MoveCursorBackMiddleReverseComposing) {
1195  auto model = std::make_unique<TextInputModel>();
1196  model->SetText("ABCDE");
1197  model->BeginComposing();
1198  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1199  EXPECT_TRUE(model->MoveCursorBack());
1200  EXPECT_EQ(model->selection(), TextRange(1));
1201  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1202  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1203 }
1204 
1205 TEST(TextInputModel, MoveCursorBackEndComposing) {
1206  auto model = std::make_unique<TextInputModel>();
1207  model->SetText("ABCDE");
1208  model->BeginComposing();
1209  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1210  EXPECT_TRUE(model->MoveCursorBack());
1211  EXPECT_EQ(model->selection(), TextRange(3));
1212  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1213  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1214 }
1215 
1216 TEST(TextInputModel, MoveCursorBackEndReverseComposing) {
1217  auto model = std::make_unique<TextInputModel>();
1218  model->SetText("ABCDE");
1219  model->BeginComposing();
1220  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1221  EXPECT_TRUE(model->MoveCursorBack());
1222  EXPECT_EQ(model->selection(), TextRange(3));
1223  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1224  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1225 }
1226 
1227 TEST(TextInputModel, MoveCursorToBeginningStart) {
1228  auto model = std::make_unique<TextInputModel>();
1229  model->SetText("ABCDE");
1230  EXPECT_TRUE(model->SetSelection(TextRange(0)));
1231  EXPECT_FALSE(model->MoveCursorToBeginning());
1232  EXPECT_EQ(model->selection(), TextRange(0));
1233  EXPECT_EQ(model->composing_range(), TextRange(0));
1234  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1235 }
1236 
1237 TEST(TextInputModel, MoveCursorToBeginningMiddle) {
1238  auto model = std::make_unique<TextInputModel>();
1239  model->SetText("ABCDE");
1240  EXPECT_TRUE(model->SetSelection(TextRange(2)));
1241  EXPECT_TRUE(model->MoveCursorToBeginning());
1242  EXPECT_EQ(model->selection(), TextRange(0));
1243  EXPECT_EQ(model->composing_range(), TextRange(0));
1244  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1245 }
1246 
1247 TEST(TextInputModel, MoveCursorToBeginningEnd) {
1248  auto model = std::make_unique<TextInputModel>();
1249  model->SetText("ABCDE");
1250  EXPECT_TRUE(model->SetSelection(TextRange(5)));
1251  EXPECT_TRUE(model->MoveCursorToBeginning());
1252  EXPECT_EQ(model->selection(), TextRange(0));
1253  EXPECT_EQ(model->composing_range(), TextRange(0));
1254  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1255 }
1256 
1257 TEST(TextInputModel, MoveCursorToBeginningSelection) {
1258  auto model = std::make_unique<TextInputModel>();
1259  model->SetText("ABCDE");
1260  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1261  EXPECT_TRUE(model->MoveCursorToBeginning());
1262  EXPECT_EQ(model->selection(), TextRange(0));
1263  EXPECT_EQ(model->composing_range(), TextRange(0));
1264  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1265 }
1266 
1267 TEST(TextInputModel, MoveCursorToBeginningReverseSelection) {
1268  auto model = std::make_unique<TextInputModel>();
1269  model->SetText("ABCDE");
1270  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1271  EXPECT_TRUE(model->MoveCursorToBeginning());
1272  EXPECT_EQ(model->selection(), TextRange(0));
1273  EXPECT_EQ(model->composing_range(), TextRange(0));
1274  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1275 }
1276 
1277 TEST(TextInputModel, MoveCursorToBeginningStartComposing) {
1278  auto model = std::make_unique<TextInputModel>();
1279  model->SetText("ABCDE");
1280  model->BeginComposing();
1281  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1282  EXPECT_FALSE(model->MoveCursorToBeginning());
1283  EXPECT_EQ(model->selection(), TextRange(1));
1284  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1285  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1286 }
1287 
1288 TEST(TextInputModel, MoveCursorToBeginningStartReverseComposing) {
1289  auto model = std::make_unique<TextInputModel>();
1290  model->SetText("ABCDE");
1291  model->BeginComposing();
1292  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 0));
1293  EXPECT_FALSE(model->MoveCursorToBeginning());
1294  EXPECT_EQ(model->selection(), TextRange(1));
1295  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1296  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1297 }
1298 
1299 TEST(TextInputModel, MoveCursorToBeginningMiddleComposing) {
1300  auto model = std::make_unique<TextInputModel>();
1301  model->SetText("ABCDE");
1302  model->BeginComposing();
1303  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1304  EXPECT_TRUE(model->MoveCursorToBeginning());
1305  EXPECT_EQ(model->selection(), TextRange(1));
1306  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1307  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1308 }
1309 
1310 TEST(TextInputModel, MoveCursorToBeginningMiddleReverseComposing) {
1311  auto model = std::make_unique<TextInputModel>();
1312  model->SetText("ABCDE");
1313  model->BeginComposing();
1314  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1315  EXPECT_TRUE(model->MoveCursorToBeginning());
1316  EXPECT_EQ(model->selection(), TextRange(1));
1317  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1318  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1319 }
1320 
1321 TEST(TextInputModel, MoveCursorToBeginningEndComposing) {
1322  auto model = std::make_unique<TextInputModel>();
1323  model->SetText("ABCDE");
1324  model->BeginComposing();
1325  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 3));
1326  EXPECT_TRUE(model->MoveCursorToBeginning());
1327  EXPECT_EQ(model->selection(), TextRange(1));
1328  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1329  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1330 }
1331 
1332 TEST(TextInputModel, MoveCursorToBeginningEndReverseComposing) {
1333  auto model = std::make_unique<TextInputModel>();
1334  model->SetText("ABCDE");
1335  model->BeginComposing();
1336  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 3));
1337  EXPECT_TRUE(model->MoveCursorToBeginning());
1338  EXPECT_EQ(model->selection(), TextRange(1));
1339  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1340  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1341 }
1342 
1343 TEST(TextInputModel, MoveCursorToEndStart) {
1344  auto model = std::make_unique<TextInputModel>();
1345  model->SetText("ABCDE");
1346  EXPECT_TRUE(model->SetSelection(TextRange(0)));
1347  EXPECT_TRUE(model->MoveCursorToEnd());
1348  EXPECT_EQ(model->selection(), TextRange(5));
1349  EXPECT_EQ(model->composing_range(), TextRange(0));
1350  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1351 }
1352 
1353 TEST(TextInputModel, MoveCursorToEndMiddle) {
1354  auto model = std::make_unique<TextInputModel>();
1355  model->SetText("ABCDE");
1356  EXPECT_TRUE(model->SetSelection(TextRange(2)));
1357  EXPECT_TRUE(model->MoveCursorToEnd());
1358  EXPECT_EQ(model->selection(), TextRange(5));
1359  EXPECT_EQ(model->composing_range(), TextRange(0));
1360  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1361 }
1362 
1363 TEST(TextInputModel, MoveCursorToEndEnd) {
1364  auto model = std::make_unique<TextInputModel>();
1365  model->SetText("ABCDE");
1366  EXPECT_TRUE(model->SetSelection(TextRange(5)));
1367  EXPECT_FALSE(model->MoveCursorToEnd());
1368  EXPECT_EQ(model->selection(), TextRange(5));
1369  EXPECT_EQ(model->composing_range(), TextRange(0));
1370  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1371 }
1372 
1373 TEST(TextInputModel, MoveCursorToEndSelection) {
1374  auto model = std::make_unique<TextInputModel>();
1375  model->SetText("ABCDE");
1376  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1377  EXPECT_TRUE(model->MoveCursorToEnd());
1378  EXPECT_EQ(model->selection(), TextRange(5));
1379  EXPECT_EQ(model->composing_range(), TextRange(0));
1380  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1381 }
1382 
1383 TEST(TextInputModel, MoveCursorToEndReverseSelection) {
1384  auto model = std::make_unique<TextInputModel>();
1385  model->SetText("ABCDE");
1386  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1387  EXPECT_TRUE(model->MoveCursorToEnd());
1388  EXPECT_EQ(model->selection(), TextRange(5));
1389  EXPECT_EQ(model->composing_range(), TextRange(0));
1390  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1391 }
1392 
1393 TEST(TextInputModel, MoveCursorToEndStartComposing) {
1394  auto model = std::make_unique<TextInputModel>();
1395  model->SetText("ABCDE");
1396  model->BeginComposing();
1397  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1398  EXPECT_TRUE(model->MoveCursorToEnd());
1399  EXPECT_EQ(model->selection(), TextRange(4));
1400  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1401  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1402 }
1403 
1404 TEST(TextInputModel, MoveCursorToEndStartReverseComposing) {
1405  auto model = std::make_unique<TextInputModel>();
1406  model->SetText("ABCDE");
1407  model->BeginComposing();
1408  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 0));
1409  EXPECT_TRUE(model->MoveCursorToEnd());
1410  EXPECT_EQ(model->selection(), TextRange(4));
1411  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1412  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1413 }
1414 
1415 TEST(TextInputModel, MoveCursorToEndMiddleComposing) {
1416  auto model = std::make_unique<TextInputModel>();
1417  model->SetText("ABCDE");
1418  model->BeginComposing();
1419  EXPECT_TRUE(model->SetComposingRange(TextRange(1, 4), 1));
1420  EXPECT_TRUE(model->MoveCursorToEnd());
1421  EXPECT_EQ(model->selection(), TextRange(4));
1422  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1423  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1424 }
1425 
1426 TEST(TextInputModel, MoveCursorToEndMiddleReverseComposing) {
1427  auto model = std::make_unique<TextInputModel>();
1428  model->SetText("ABCDE");
1429  model->BeginComposing();
1430  EXPECT_TRUE(model->SetComposingRange(TextRange(4, 1), 1));
1431  EXPECT_TRUE(model->MoveCursorToEnd());
1432  EXPECT_EQ(model->selection(), TextRange(4));
1433  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1434  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1435 }
1436 
1437 TEST(TextInputModel, MoveCursorToEndEndComposing) {
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_FALSE(model->MoveCursorToEnd());
1443  EXPECT_EQ(model->selection(), TextRange(4));
1444  EXPECT_EQ(model->composing_range(), TextRange(1, 4));
1445  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1446 }
1447 
1448 TEST(TextInputModel, MoveCursorToEndEndReverseComposing) {
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_FALSE(model->MoveCursorToEnd());
1454  EXPECT_EQ(model->selection(), TextRange(4));
1455  EXPECT_EQ(model->composing_range(), TextRange(4, 1));
1456  EXPECT_STREQ(model->GetText().c_str(), "ABCDE");
1457 }
1458 
1459 TEST(TextInputModel, GetCursorOffset) {
1460  auto model = std::make_unique<TextInputModel>();
1461  // These characters take 1, 2, 3 and 4 bytes in UTF-8.
1462  model->SetText("$¢€𐍈");
1463  EXPECT_TRUE(model->SetSelection(TextRange(0)));
1464  EXPECT_EQ(model->GetCursorOffset(), 0);
1465  EXPECT_TRUE(model->MoveCursorForward());
1466  EXPECT_EQ(model->GetCursorOffset(), 1);
1467  EXPECT_TRUE(model->MoveCursorForward());
1468  EXPECT_EQ(model->GetCursorOffset(), 3);
1469  EXPECT_TRUE(model->MoveCursorForward());
1470  EXPECT_EQ(model->GetCursorOffset(), 6);
1471  EXPECT_TRUE(model->MoveCursorForward());
1472  EXPECT_EQ(model->GetCursorOffset(), 10);
1473 }
1474 
1475 TEST(TextInputModel, GetCursorOffsetSelection) {
1476  auto model = std::make_unique<TextInputModel>();
1477  model->SetText("ABCDE");
1478  EXPECT_TRUE(model->SetSelection(TextRange(1, 4)));
1479  EXPECT_EQ(model->GetCursorOffset(), 4);
1480 }
1481 
1482 TEST(TextInputModel, GetCursorOffsetReverseSelection) {
1483  auto model = std::make_unique<TextInputModel>();
1484  model->SetText("ABCDE");
1485  EXPECT_TRUE(model->SetSelection(TextRange(4, 1)));
1486  EXPECT_EQ(model->GetCursorOffset(), 1);
1487 }
1488 
1489 } // namespace flutter
TEST(DartServiceIsolateTest, CanAddAndRemoveHandles)