From b04454345101da19fd8a8defb3e98147f99f1188 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 23 Apr 2021 10:19:15 -0400 Subject: [PATCH] Bug 573064: Test for full clear - extended "E3" capability Change-Id: Ic30dac68f870f04808eb9038c2ba61b1da9e983f --- .../terminal/emulator/VT100EmulatorTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorTest.java b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorTest.java index 32995d2bb6d..8f9d674508e 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorTest.java +++ b/terminal/plugins/org.eclipse.tm.terminal.test/src/org/eclipse/tm/internal/terminal/emulator/VT100EmulatorTest.java @@ -33,6 +33,8 @@ public class VT100EmulatorTest { private static final int WINDOW_LINES = 24; private static final String CLEAR_CURSOR_TO_EOL = "\033[K"; private static final String CURSOR_POSITION_TOP_LEFT = "\033[H"; + private static final String CLEAR_ENTIRE_SCREEN_AND_SCROLLBACK = "\033[3J"; + private static final String CLEAR_ENTIRE_SCREEN = "\033[2J"; private static String TITLE(String title) { return "\033]0;" + title + "\007"; @@ -226,4 +228,36 @@ public class VT100EmulatorTest { () -> assertEquals(List.of("TITLE1", "TITLE2"), control.getAllTitles())); } + @Test + public void testE3ClearScreenAndScrollback() { + data.setMaxHeight(1000); + List expected = new ArrayList<>(); + for (int i = 0; i < 1000; i++) { + String line = "Hello " + i; + run(line + "\r\n"); + expected.add(line); + } + expected.remove(0); + assertAll(() -> assertCursorLocation(999, 0), () -> assertTextEquals(expected)); + run(CLEAR_ENTIRE_SCREEN_AND_SCROLLBACK); + assertAll(() -> assertTextEquals("")); + } + + /** + * Runs what "clear" command does on modern Linux installs, including E3 extension + */ + @Test + public void testClear() { + data.setMaxHeight(1000); + List expected = new ArrayList<>(); + for (int i = 0; i < 1000; i++) { + String line = "Hello " + i; + run(line + "\r\n"); + expected.add(line); + } + expected.remove(0); + assertAll(() -> assertCursorLocation(999, 0), () -> assertTextEquals(expected)); + run(CURSOR_POSITION_TOP_LEFT + CLEAR_ENTIRE_SCREEN + CLEAR_ENTIRE_SCREEN_AND_SCROLLBACK); + assertAll(() -> assertCursorLocation(0, 0), () -> assertTextEquals("")); + } }