|
28 | 28 |
|
29 | 29 | public class ConsoleFeatureIT extends AbstractViewTest { |
30 | 30 |
|
| 31 | + /** Returns a line that runs up to the right margin */ |
| 32 | + private String makeFullLine(XTermElement term, boolean hasPrompt) { |
| 33 | + int cols = term.getColumnWidth(); |
| 34 | + int x = hasPrompt ? term.cursorPosition().x : 0; |
| 35 | + return StringUtils.repeat("0123456789", cols / 10 + 1).substring(0, cols - x); |
| 36 | + } |
| 37 | + |
31 | 38 | @Test |
32 | 39 | public void testFeature() throws InterruptedException { |
33 | 40 | XTermElement term = $(XTermElement.class).first(); |
@@ -67,41 +74,42 @@ public void testFeature() throws InterruptedException { |
67 | 74 | term.sendKeys(Keys.INSERT, "C"); |
68 | 75 | assertThat(term.currentLine(), is("ABCLL")); |
69 | 76 |
|
70 | | - // long line |
71 | | - |
72 | | - int cols = term.getColumnWidth(); |
73 | | - String text = StringUtils.repeat("0123456789", cols / 10 + 1).substring(0, cols); |
74 | 77 |
|
| 78 | + // long line |
75 | 79 | term.sendKeys("\n"); |
76 | 80 | assertThat(term.currentLine(), is("")); |
77 | 81 | assertThat(term.cursorPosition(), is(pos.advance(0, 1))); |
78 | 82 |
|
| 83 | + String prompt = term.lineAtOffset(0); |
| 84 | + String text = makeFullLine(term, true); |
| 85 | + int cols = text.length(); |
| 86 | + |
79 | 87 | term.sendKeys(text); |
80 | 88 | term.sendKeys(Keys.HOME); |
81 | 89 | assertThat(term.cursorPosition(), is(pos)); |
82 | 90 | assertThat(term.currentLine(), is(text)); |
83 | 91 |
|
84 | 92 | term.sendKeys("A"); |
85 | | - assertThat(term.currentLine(), is("A" + text.substring(0, cols - 1))); |
86 | | - assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1))); |
| 93 | + assertThat(term.lineAtOffset(0), is(prompt + "A" + text.substring(0, cols - 1))); |
| 94 | + assertThat(term.lineAtOffset(1), is(text.substring(cols - 1))); |
87 | 95 |
|
88 | 96 | term.sendKeys("B"); |
89 | | - assertThat(term.currentLine(), is("AB" + text.substring(0, cols - 2))); |
90 | | - assertThat(term.lineAtOffset(+1), is(text.substring(cols - 2))); |
| 97 | + assertThat(term.lineAtOffset(0), is(prompt + "AB" + text.substring(0, cols - 2))); |
| 98 | + assertThat(term.lineAtOffset(1), is(text.substring(cols - 2))); |
91 | 99 |
|
92 | 100 | term.sendKeys(Keys.END); |
93 | | - assertThat(term.cursorPosition(), is(pos.plus(2, 1))); |
| 101 | + assertThat(term.cursorPosition(), is(new Position(2, pos.y + 1))); |
94 | 102 |
|
95 | 103 | term.sendKeys(Keys.HOME); |
96 | 104 | assertThat(term.cursorPosition(), is(pos)); |
97 | 105 |
|
98 | 106 | term.sendKeys(Keys.DELETE); |
99 | | - assertThat(term.currentLine(), is("B" + text.substring(0, cols - 1))); |
100 | | - assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1))); |
| 107 | + assertThat(term.lineAtOffset(0), is(prompt + "B" + text.substring(0, cols - 1))); |
| 108 | + assertThat(term.lineAtOffset(1), is(text.substring(cols - 1))); |
101 | 109 |
|
102 | 110 | term.sendKeys(Keys.DELETE); |
103 | | - assertThat(term.currentLine(), is(text)); |
104 | | - assertThat(term.lineAtOffset(+1), isEmptyString()); |
| 111 | + assertThat(term.lineAtOffset(0), is(prompt + text)); |
| 112 | + assertThat(term.lineAtOffset(1), isEmptyString()); |
105 | 113 | } |
106 | 114 |
|
107 | 115 | @Test |
|
0 commit comments