6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8080679
27 * @modules jdk.internal.le/jdk.internal.jline.console
28 * @summary Verify ConsoleReader.stripAnsi strips escape sequences from its input correctly.
29 */
30
31 import java.io.ByteArrayInputStream;
32 import java.io.ByteArrayOutputStream;
33 import java.lang.reflect.Method;
34 import jdk.internal.jline.console.ConsoleReader;
35
36 public class StripAnsiTest {
37 public static void main(String... args) throws Exception {
38 new StripAnsiTest().run();
39 }
40
41 void run() throws Exception {
42 ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
43 ByteArrayOutputStream out = new ByteArrayOutputStream();
44 ConsoleReader reader = new ConsoleReader(in, out);
45
46 String withAnsi = "0\033[s1\033[2J2\033[37;4m3";
47 String expected = "0123";
48
49 Method stripAnsi = ConsoleReader.class.getDeclaredMethod("stripAnsi", String.class);
50 stripAnsi.setAccessible(true);
51 String actual = (String) stripAnsi.invoke(reader, withAnsi);
52
53 if (!expected.equals(actual)) {
54 throw new IllegalStateException("Did not correctly strip escape sequences: " + actual);
55 }
56 }
57 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8080679 8131913
27 * @modules jdk.internal.le/jdk.internal.jline
28 * jdk.internal.le/jdk.internal.jline.console
29 * @summary Verify ConsoleReader.stripAnsi strips escape sequences from its input correctly.
30 */
31
32 import java.io.ByteArrayInputStream;
33 import java.io.ByteArrayOutputStream;
34 import java.lang.reflect.Method;
35 import jdk.internal.jline.UnsupportedTerminal;
36 import jdk.internal.jline.console.ConsoleReader;
37
38 public class StripAnsiTest {
39 public static void main(String... args) throws Exception {
40 new StripAnsiTest().run();
41 }
42
43 void run() throws Exception {
44 ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
45 ByteArrayOutputStream out = new ByteArrayOutputStream();
46 ConsoleReader reader = new ConsoleReader(in, out, new UnsupportedTerminal());
47
48 String withAnsi = "0\033[s1\033[2J2\033[37;4m3";
49 String expected = "0123";
50
51 Method stripAnsi = ConsoleReader.class.getDeclaredMethod("stripAnsi", String.class);
52 stripAnsi.setAccessible(true);
53 String actual = (String) stripAnsi.invoke(reader, withAnsi);
54
55 if (!expected.equals(actual)) {
56 throw new IllegalStateException("Did not correctly strip escape sequences: " + actual);
57 }
58 }
59 }
|