Skip to content

Commit 32d32e6

Browse files
javier-godoypaodb
authored andcommitted
test: update integration tests for the new prompt feature
1 parent 0fbc71b commit 32d32e6

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/ClipboardFeatureIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private static int[] intArray(Object obj) {
3535
public void testFeature() {
3636
XTermElement term = $(XTermElement.class).first();
3737

38+
term.setPrompt(null);
3839
term.write("\\x1bcTEXT");
3940

4041
int[] size =

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/ConsoleFeatureIT.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828

2929
public class ConsoleFeatureIT extends AbstractViewTest {
3030

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+
3138
@Test
3239
public void testFeature() throws InterruptedException {
3340
XTermElement term = $(XTermElement.class).first();
@@ -67,41 +74,42 @@ public void testFeature() throws InterruptedException {
6774
term.sendKeys(Keys.INSERT, "C");
6875
assertThat(term.currentLine(), is("ABCLL"));
6976

70-
// long line
71-
72-
int cols = term.getColumnWidth();
73-
String text = StringUtils.repeat("0123456789", cols / 10 + 1).substring(0, cols);
7477

78+
// long line
7579
term.sendKeys("\n");
7680
assertThat(term.currentLine(), is(""));
7781
assertThat(term.cursorPosition(), is(pos.advance(0, 1)));
7882

83+
String prompt = term.lineAtOffset(0);
84+
String text = makeFullLine(term, true);
85+
int cols = text.length();
86+
7987
term.sendKeys(text);
8088
term.sendKeys(Keys.HOME);
8189
assertThat(term.cursorPosition(), is(pos));
8290
assertThat(term.currentLine(), is(text));
8391

8492
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)));
8795

8896
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)));
9199

92100
term.sendKeys(Keys.END);
93-
assertThat(term.cursorPosition(), is(pos.plus(2, 1)));
101+
assertThat(term.cursorPosition(), is(new Position(2, pos.y + 1)));
94102

95103
term.sendKeys(Keys.HOME);
96104
assertThat(term.cursorPosition(), is(pos));
97105

98106
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)));
101109

102110
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());
105113
}
106114

107115
@Test

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/TerminalHistoryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void testArrowKeys() {
1616
term.sendKeys("foo1\nfoo2\n");
1717

1818
assertThat(term.cursorPosition(), is(pos.advance(0, 2)));
19-
assertThat(term.lineAtOffset(0), isEmptyString());
19+
assertThat(term.currentLine(), isEmptyString());
2020

2121
term.sendKeys(Keys.ARROW_UP);
2222
assertThat(term.currentLine(), is("foo2"));
@@ -42,7 +42,7 @@ public void testArrowKeysAndRestore() {
4242
term.sendKeys("foo1\nfoo2\n");
4343

4444
assertThat(term.cursorPosition(), is(pos.advance(0, 2)));
45-
assertThat(term.lineAtOffset(0), isEmptyString());
45+
assertThat(term.currentLine(), isEmptyString());
4646

4747
term.sendKeys("bar");
4848
term.sendKeys(Keys.ARROW_UP);

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/XTermElement.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ public int getColumnWidth() {
2929
}
3030

3131
final String currentLine() {
32-
return lineAtOffset(0);
32+
return getPropertyString("currentLine");
3333
}
3434

3535
public String lineAtOffset(int offset) {
36-
String command =
37-
"buffer=arguments[0].terminal._core._inputHandler._bufferService.buffer; return buffer.lines.get(buffer.ybase+buffer.y+(%s)).translateToString()";
38-
command = String.format(command, offset);
39-
return ((String) executeScript(command, this)).replaceFirst("\\s+$", "");
36+
return ((String) executeScript(
37+
"buffer=arguments[0].terminal._core._inputHandler._bufferService.buffer;"
38+
+ "line=buffer.lines.get(buffer.ybase+buffer.y+(arguments[1]));"
39+
+ "return line.translateToString().substr(0,line.getTrimmedLength());",
40+
this, offset));
4041
}
4142

4243
public Position cursorPosition() {

0 commit comments

Comments
 (0)