@@ -46,7 +46,10 @@ TEST(TextInputModel, SetEditingStateSelection) {
4646
4747TEST (TextInputModel, SetEditingStateReverseSelection) {
4848 auto model = std::make_unique<TextInputModel>();
49- EXPECT_FALSE (model->SetEditingState (3 , 1 , " ABCDE" ));
49+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
50+ EXPECT_EQ (model->selection_base (), 4 );
51+ EXPECT_EQ (model->selection_extent (), 1 );
52+ EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
5053}
5154
5255TEST (TextInputModel, SetEditingStateOutsideString) {
@@ -85,6 +88,15 @@ TEST(TextInputModel, AddCodePointSelection) {
8588 EXPECT_STREQ (model->GetText ().c_str (), " AxE" );
8689}
8790
91+ TEST (TextInputModel, AddCodePointReverseSelection) {
92+ auto model = std::make_unique<TextInputModel>();
93+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
94+ model->AddCodePoint (' x' );
95+ EXPECT_EQ (model->selection_base (), 2 );
96+ EXPECT_EQ (model->selection_extent (), 2 );
97+ EXPECT_STREQ (model->GetText ().c_str (), " AxE" );
98+ }
99+
88100TEST (TextInputModel, AddCodePointSelectionWideCharacter) {
89101 auto model = std::make_unique<TextInputModel>();
90102 EXPECT_TRUE (model->SetEditingState (1 , 4 , " ABCDE" ));
@@ -94,6 +106,15 @@ TEST(TextInputModel, AddCodePointSelectionWideCharacter) {
94106 EXPECT_STREQ (model->GetText ().c_str (), " A😄E" );
95107}
96108
109+ TEST (TextInputModel, AddCodePointReverseSelectionWideCharacter) {
110+ auto model = std::make_unique<TextInputModel>();
111+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
112+ model->AddCodePoint (0x1f604 );
113+ EXPECT_EQ (model->selection_base (), 3 );
114+ EXPECT_EQ (model->selection_extent (), 3 );
115+ EXPECT_STREQ (model->GetText ().c_str (), " A😄E" );
116+ }
117+
97118TEST (TextInputModel, AddText) {
98119 auto model = std::make_unique<TextInputModel>();
99120 model->AddText (u" ABCDE" );
@@ -113,6 +134,15 @@ TEST(TextInputModel, AddTextSelection) {
113134 EXPECT_STREQ (model->GetText ().c_str (), " AxyE" );
114135}
115136
137+ TEST (TextInputModel, AddTextReverseSelection) {
138+ auto model = std::make_unique<TextInputModel>();
139+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
140+ model->AddText (" xy" );
141+ EXPECT_EQ (model->selection_base (), 3 );
142+ EXPECT_EQ (model->selection_extent (), 3 );
143+ EXPECT_STREQ (model->GetText ().c_str (), " AxyE" );
144+ }
145+
116146TEST (TextInputModel, AddTextSelectionWideCharacter) {
117147 auto model = std::make_unique<TextInputModel>();
118148 EXPECT_TRUE (model->SetEditingState (1 , 4 , " ABCDE" ));
@@ -122,6 +152,15 @@ TEST(TextInputModel, AddTextSelectionWideCharacter) {
122152 EXPECT_STREQ (model->GetText ().c_str (), " A😄🙃E" );
123153}
124154
155+ TEST (TextInputModel, AddTextReverseSelectionWideCharacter) {
156+ auto model = std::make_unique<TextInputModel>();
157+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
158+ model->AddText (u" 😄🙃" );
159+ EXPECT_EQ (model->selection_base (), 5 );
160+ EXPECT_EQ (model->selection_extent (), 5 );
161+ EXPECT_STREQ (model->GetText ().c_str (), " A😄🙃E" );
162+ }
163+
125164TEST (TextInputModel, DeleteStart) {
126165 auto model = std::make_unique<TextInputModel>();
127166 EXPECT_TRUE (model->SetEditingState (0 , 0 , " ABCDE" ));
@@ -167,6 +206,15 @@ TEST(TextInputModel, DeleteSelection) {
167206 EXPECT_STREQ (model->GetText ().c_str (), " AE" );
168207}
169208
209+ TEST (TextInputModel, DeleteReverseSelection) {
210+ auto model = std::make_unique<TextInputModel>();
211+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
212+ ASSERT_TRUE (model->Delete ());
213+ EXPECT_EQ (model->selection_base (), 1 );
214+ EXPECT_EQ (model->selection_extent (), 1 );
215+ EXPECT_STREQ (model->GetText ().c_str (), " AE" );
216+ }
217+
170218TEST (TextInputModel, DeleteSurroundingAtCursor) {
171219 auto model = std::make_unique<TextInputModel>();
172220 model->SetEditingState (2 , 2 , " ABCDE" );
@@ -257,6 +305,15 @@ TEST(TextInputModel, DeleteSurroundingSelection) {
257305 EXPECT_STREQ (model->GetText ().c_str (), " ABCE" );
258306}
259307
308+ TEST (TextInputModel, DeleteSurroundingReverseSelection) {
309+ auto model = std::make_unique<TextInputModel>();
310+ model->SetEditingState (4 , 3 , " ABCDE" );
311+ EXPECT_TRUE (model->DeleteSurrounding (0 , 1 ));
312+ EXPECT_EQ (model->selection_base (), 3 );
313+ EXPECT_EQ (model->selection_extent (), 3 );
314+ EXPECT_STREQ (model->GetText ().c_str (), " ABCE" );
315+ }
316+
260317TEST (TextInputModel, BackspaceStart) {
261318 auto model = std::make_unique<TextInputModel>();
262319 EXPECT_TRUE (model->SetEditingState (0 , 0 , " ABCDE" ));
@@ -302,6 +359,15 @@ TEST(TextInputModel, BackspaceSelection) {
302359 EXPECT_STREQ (model->GetText ().c_str (), " AE" );
303360}
304361
362+ TEST (TextInputModel, BackspaceReverseSelection) {
363+ auto model = std::make_unique<TextInputModel>();
364+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
365+ ASSERT_TRUE (model->Delete ());
366+ EXPECT_EQ (model->selection_base (), 1 );
367+ EXPECT_EQ (model->selection_extent (), 1 );
368+ EXPECT_STREQ (model->GetText ().c_str (), " AE" );
369+ }
370+
305371TEST (TextInputModel, MoveCursorForwardStart) {
306372 auto model = std::make_unique<TextInputModel>();
307373 EXPECT_TRUE (model->SetEditingState (0 , 0 , " ABCDE" ));
@@ -347,6 +413,15 @@ TEST(TextInputModel, MoveCursorForwardSelection) {
347413 EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
348414}
349415
416+ TEST (TextInputModel, MoveCursorForwardReverseSelection) {
417+ auto model = std::make_unique<TextInputModel>();
418+ EXPECT_TRUE (model->SetEditingState (4 , 1 , " ABCDE" ));
419+ EXPECT_TRUE (model->MoveCursorForward ());
420+ EXPECT_EQ (model->selection_base (), 4 );
421+ EXPECT_EQ (model->selection_extent (), 4 );
422+ EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
423+ }
424+
350425TEST (TextInputModel, MoveCursorBackStart) {
351426 auto model = std::make_unique<TextInputModel>();
352427 EXPECT_TRUE (model->SetEditingState (0 , 0 , " ABCDE" ));
@@ -392,6 +467,15 @@ TEST(TextInputModel, MoveCursorBackSelection) {
392467 EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
393468}
394469
470+ TEST (TextInputModel, MoveCursorBackReverseSelection) {
471+ auto model = std::make_unique<TextInputModel>();
472+ model->SetEditingState (4 , 1 , " ABCDE" );
473+ EXPECT_TRUE (model->MoveCursorBack ());
474+ EXPECT_EQ (model->selection_base (), 1 );
475+ EXPECT_EQ (model->selection_extent (), 1 );
476+ EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
477+ }
478+
395479TEST (TextInputModel, MoveCursorToBeginningStart) {
396480 auto model = std::make_unique<TextInputModel>();
397481 model->SetEditingState (0 , 0 , " ABCDE" );
@@ -428,6 +512,15 @@ TEST(TextInputModel, MoveCursorToBeginningSelection) {
428512 EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
429513}
430514
515+ TEST (TextInputModel, MoveCursorToBeginningReverseSelection) {
516+ auto model = std::make_unique<TextInputModel>();
517+ model->SetEditingState (4 , 1 , " ABCDE" );
518+ EXPECT_TRUE (model->MoveCursorToBeginning ());
519+ EXPECT_EQ (model->selection_base (), 0 );
520+ EXPECT_EQ (model->selection_extent (), 0 );
521+ EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
522+ }
523+
431524TEST (TextInputModel, MoveCursorToEndStart) {
432525 auto model = std::make_unique<TextInputModel>();
433526 model->SetEditingState (0 , 0 , " ABCDE" );
@@ -464,6 +557,15 @@ TEST(TextInputModel, MoveCursorToEndSelection) {
464557 EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
465558}
466559
560+ TEST (TextInputModel, MoveCursorToEndReverseSelection) {
561+ auto model = std::make_unique<TextInputModel>();
562+ model->SetEditingState (4 , 1 , " ABCDE" );
563+ EXPECT_TRUE (model->MoveCursorToEnd ());
564+ EXPECT_EQ (model->selection_base (), 5 );
565+ EXPECT_EQ (model->selection_extent (), 5 );
566+ EXPECT_STREQ (model->GetText ().c_str (), " ABCDE" );
567+ }
568+
467569TEST (TextInputModel, GetCursorOffset) {
468570 auto model = std::make_unique<TextInputModel>();
469571 // These characters take 1, 2, 3 and 4 bytes in UTF-8.
@@ -485,4 +587,10 @@ TEST(TextInputModel, GetCursorOffsetSelection) {
485587 EXPECT_EQ (model->GetCursorOffset (), 4 );
486588}
487589
590+ TEST (TextInputModel, GetCursorOffsetReverseSelection) {
591+ auto model = std::make_unique<TextInputModel>();
592+ model->SetEditingState (4 , 1 , " ABCDE" );
593+ EXPECT_EQ (model->GetCursorOffset (), 1 );
594+ }
595+
488596} // namespace flutter
0 commit comments