From 77d25288763d144cdaa80681d76f3b78a4062c8b Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 21 Nov 2016 13:55:31 +0100 Subject: [PATCH] Use UTF-8 in all tests, #3 --- .../java/org/jline/keymap/BindingReaderTest.java | 7 ++++--- .../org/jline/reader/impl/MultiByteCharTest.java | 4 ++-- .../org/jline/reader/impl/ReaderTestSupport.java | 16 ++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/jline/keymap/BindingReaderTest.java b/src/test/java/org/jline/keymap/BindingReaderTest.java index 8e4889200..6592ecd9d 100644 --- a/src/test/java/org/jline/keymap/BindingReaderTest.java +++ b/src/test/java/org/jline/keymap/BindingReaderTest.java @@ -10,6 +10,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.nio.charset.Charset; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; @@ -44,13 +45,13 @@ public void setUp() throws Exception { in = new EofPipedInputStream(); out = new ByteArrayOutputStream(); - terminal = new DumbTerminal(in, out); + terminal = new DumbTerminal("dumb", "dumb", in, out, "UTF-8"); terminal.setSize(new Size(160, 80)); } @Test public void testBindingReaderNoUnicode() { - in.setIn(new ByteArrayInputStream("\uD834\uDD21abc".getBytes())); + in.setIn(new ByteArrayInputStream("\uD834\uDD21abc".getBytes(Charset.forName("UTF-8")))); BindingReader reader = new BindingReader(terminal.reader()); KeyMap keyMap = new KeyMap<>(); keyMap.bind(new Reference("foo"), "b"); @@ -61,7 +62,7 @@ public void testBindingReaderNoUnicode() { @Test public void testBindingReaderUnicode() { - in.setIn(new ByteArrayInputStream("\uD834\uDD21abc".getBytes())); + in.setIn(new ByteArrayInputStream("\uD834\uDD21abc".getBytes(Charset.forName("UTF-8")))); BindingReader reader = new BindingReader(terminal.reader()); KeyMap keyMap = new KeyMap<>(); keyMap.setUnicode(new Reference("insert")); diff --git a/src/test/java/org/jline/reader/impl/MultiByteCharTest.java b/src/test/java/org/jline/reader/impl/MultiByteCharTest.java index 7d8680c9c..d12950726 100644 --- a/src/test/java/org/jline/reader/impl/MultiByteCharTest.java +++ b/src/test/java/org/jline/reader/impl/MultiByteCharTest.java @@ -27,8 +27,8 @@ public void testInputStreamReader() throws IOException { PipedOutputStream pos = new PipedOutputStream(); PipedInputStream pis = new PipedInputStream(pos); - pos.write(str.getBytes(Charset.defaultCharset())); - Reader r = new InputStreamReader(pis, Charset.defaultCharset()); + pos.write(str.getBytes(Charset.forName("UTF-8"))); + Reader r = new InputStreamReader(pis, Charset.forName("UTF-8")); int c0 = r.read(); int c1 = r.read(); int c2 = r.read(); diff --git a/src/test/java/org/jline/reader/impl/ReaderTestSupport.java b/src/test/java/org/jline/reader/impl/ReaderTestSupport.java index df4e6a092..f6f9ee8a0 100644 --- a/src/test/java/org/jline/reader/impl/ReaderTestSupport.java +++ b/src/test/java/org/jline/reader/impl/ReaderTestSupport.java @@ -8,11 +8,7 @@ */ package org.jline.reader.impl; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; +import java.io.*; import java.nio.charset.Charset; import java.util.List; import java.util.Map; @@ -68,7 +64,7 @@ public void setUp() throws Exception { in = new EofPipedInputStream(); out = new ByteArrayOutputStream(); - terminal = new DumbTerminal("terminal", "ansi", in, out, Charset.defaultCharset().name()); + terminal = new DumbTerminal("terminal", "ansi", in, out, "UTF-8"); terminal.setSize(new Size(160, 80)); reader = new TestLineReader(terminal, "JLine", null); reader.setKeyMap(LineReaderImpl.EMACS); @@ -182,7 +178,11 @@ public TestBuffer(char[] chars) { @Override public String toString() { - return out.toString(); + try { + return out.toString("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } public byte[] getBytes() { @@ -271,7 +271,7 @@ public TestBuffer down() { } public TestBuffer append(final String str) { - for (byte b : str.getBytes()) { + for (byte b : str.getBytes(Charset.forName("UTF-8"))) { append(b); } return this;