Flutter Engine
The Flutter Engine
TextEditingDeltaTest.java
Go to the documentation of this file.
1package io.flutter.plugin.editing;
2
3import static org.junit.Assert.assertEquals;
4
5import androidx.test.ext.junit.runners.AndroidJUnit4;
6import org.junit.Before;
7import org.junit.Test;
8import org.junit.runner.RunWith;
9import org.mockito.MockitoAnnotations;
10import org.robolectric.annotation.Config;
11
12@Config(manifest = Config.NONE)
13@RunWith(AndroidJUnit4.class)
15 @Before
16 public void setUp() {
17 MockitoAnnotations.openMocks(this);
18 }
19
20 @Test
22 final CharSequence oldText = "hell";
23 final CharSequence textAfterChange = "hello";
24
25 final int oldComposingStart = 0;
26 final int oldComposingEnd = 4;
27
28 final int startOfReplacementText = 0;
29 final int endOfReplacementText = textAfterChange.length();
30
31 final int newSelectionStart = 5;
32 final int newSelectionEnd = 5;
33 final int newComposingStart = 0;
34 final int newComposingEnd = 5;
35
38 oldText,
39 oldComposingStart,
40 oldComposingEnd,
41 textAfterChange,
42 newSelectionStart,
43 newSelectionEnd,
44 newComposingStart,
45 newComposingEnd);
46
47 assertEquals(oldText, delta.getOldText());
48 assertEquals(textAfterChange, delta.getDeltaText());
49 assertEquals(oldComposingStart, delta.getDeltaStart());
50 assertEquals(oldComposingEnd, delta.getDeltaEnd());
51 assertEquals(newSelectionStart, delta.getNewSelectionStart());
52 assertEquals(newSelectionEnd, delta.getNewSelectionEnd());
53 assertEquals(newComposingStart, delta.getNewComposingStart());
54 assertEquals(newComposingEnd, delta.getNewComposingEnd());
55 }
56
57 @Test
59 final CharSequence oldText = "hello";
60
61 final int newSelectionStart = 3;
62 final int newSelectionEnd = 3;
63 final int newComposingStart = 0;
64 final int newComposingEnd = 5;
65
68 oldText, newSelectionStart, newSelectionEnd, newComposingStart, newComposingEnd);
69
70 assertEquals(oldText, delta.getOldText());
71 assertEquals("", delta.getDeltaText());
72 assertEquals(-1, delta.getDeltaStart());
73 assertEquals(-1, delta.getDeltaEnd());
74 assertEquals(newSelectionStart, delta.getNewSelectionStart());
75 assertEquals(newSelectionEnd, delta.getNewSelectionEnd());
76 assertEquals(newComposingStart, delta.getNewComposingStart());
77 assertEquals(newComposingEnd, delta.getNewComposingEnd());
78 }
79}