Skip to content

Commit

Permalink
Use UTF-8 in all tests, #3
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 21, 2016
1 parent 094828f commit 77d2528
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/test/java/org/jline/keymap/BindingReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Binding> keyMap = new KeyMap<>();
keyMap.bind(new Reference("foo"), "b");
Expand All @@ -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<Binding> keyMap = new KeyMap<>();
keyMap.setUnicode(new Reference("insert"));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jline/reader/impl/MultiByteCharTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/jline/reader/impl/ReaderTestSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 77d2528

Please sign in to comment.