terminal-emulator: tests: change spaces to tabs for consistency

This commit is contained in:
Henrik Grimler
2021-01-02 09:01:28 +01:00
parent a0298285e3
commit 7d31b7f480
10 changed files with 154 additions and 154 deletions

View File

@@ -17,13 +17,13 @@ public class ByteQueueTest extends TestCase {
public void testCompleteWrites() throws Exception { public void testCompleteWrites() throws Exception {
ByteQueue q = new ByteQueue(10); ByteQueue q = new ByteQueue(10);
assertTrue(q.write(new byte[]{1, 2, 3}, 0, 3)); assertTrue(q.write(new byte[]{1, 2, 3}, 0, 3));
byte[] arr = new byte[10]; byte[] arr = new byte[10];
assertEquals(3, q.read(arr, true)); assertEquals(3, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3}, new byte[]{arr[0], arr[1], arr[2]}); assertArrayEquals(new byte[]{1, 2, 3}, new byte[]{arr[0], arr[1], arr[2]});
assertTrue(q.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 10)); assertTrue(q.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 10));
assertEquals(10, q.read(arr, true)); assertEquals(10, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, arr); assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, arr);
} }
@@ -43,7 +43,7 @@ public class ByteQueueTest extends TestCase {
public void testWriteNotesClosing() throws Exception { public void testWriteNotesClosing() throws Exception {
ByteQueue q = new ByteQueue(10); ByteQueue q = new ByteQueue(10);
q.close(); q.close();
assertFalse(q.write(new byte[]{1, 2, 3}, 0, 3)); assertFalse(q.write(new byte[]{1, 2, 3}, 0, 3));
} }
public void testReadNonBlocking() throws Exception { public void testReadNonBlocking() throws Exception {

View File

@@ -35,31 +35,31 @@ public class ControlSequenceIntroducerTest extends TerminalTestCase {
withTerminalSized(3, 2).enterString("\033[0;38;2;255;255;255;48;2;0;0;0;1;2;3;4;5;7;8;9mabc").assertLinesAre("abc", " "); withTerminalSized(3, 2).enterString("\033[0;38;2;255;255;255;48;2;0;0;0;1;2;3;4;5;7;8;9mabc").assertLinesAre("abc", " ");
} }
/** CSI Ps b Repeat the preceding graphic character Ps times (REP). */ /** CSI Ps b Repeat the preceding graphic character Ps times (REP). */
public void testRepeat() { public void testRepeat() {
withTerminalSized(3, 2).enterString("a\033[b").assertLinesAre("aa ", " "); withTerminalSized(3, 2).enterString("a\033[b").assertLinesAre("aa ", " ");
withTerminalSized(3, 2).enterString("a\033[2b").assertLinesAre("aaa", " "); withTerminalSized(3, 2).enterString("a\033[2b").assertLinesAre("aaa", " ");
// When no char has been output we ignore REP: // When no char has been output we ignore REP:
withTerminalSized(3, 2).enterString("\033[b").assertLinesAre(" ", " "); withTerminalSized(3, 2).enterString("\033[b").assertLinesAre(" ", " ");
// This shows that REP outputs the last emitted code point and not the one relative to the // This shows that REP outputs the last emitted code point and not the one relative to the
// current cursor position: // current cursor position:
withTerminalSized(5, 2).enterString("abcde\033[2G\033[2b\n").assertLinesAre("aeede", " "); withTerminalSized(5, 2).enterString("abcde\033[2G\033[2b\n").assertLinesAre("aeede", " ");
} }
/** CSI 3 J Clear scrollback (xterm, libvte; non-standard). */ /** CSI 3 J Clear scrollback (xterm, libvte; non-standard). */
public void testCsi3J() { public void testCsi3J() {
withTerminalSized(3, 2).enterString("a\r\nb\r\nc\r\nd"); withTerminalSized(3, 2).enterString("a\r\nb\r\nc\r\nd");
assertEquals("a\nb\nc\nd", mTerminal.getScreen().getTranscriptText()); assertEquals("a\nb\nc\nd", mTerminal.getScreen().getTranscriptText());
enterString("\033[3J"); enterString("\033[3J");
assertEquals("c\nd", mTerminal.getScreen().getTranscriptText()); assertEquals("c\nd", mTerminal.getScreen().getTranscriptText());
withTerminalSized(3, 2).enterString("Lorem_ipsum"); withTerminalSized(3, 2).enterString("Lorem_ipsum");
assertEquals("Lorem_ipsum", mTerminal.getScreen().getTranscriptText()); assertEquals("Lorem_ipsum", mTerminal.getScreen().getTranscriptText());
enterString("\033[3J"); enterString("\033[3J");
assertEquals("ipsum", mTerminal.getScreen().getTranscriptText()); assertEquals("ipsum", mTerminal.getScreen().getTranscriptText());
withTerminalSized(3, 2).enterString("w\r\nx\r\ny\r\nz\033[?1049h\033[3J\033[?1049l"); withTerminalSized(3, 2).enterString("w\r\nx\r\ny\r\nz\033[?1049h\033[3J\033[?1049l");
assertEquals("y\nz", mTerminal.getScreen().getTranscriptText()); assertEquals("y\nz", mTerminal.getScreen().getTranscriptText());
} }
} }

View File

@@ -18,7 +18,7 @@ public class CursorAndScreenTest extends TerminalTestCase {
assertLinesAre("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY"); assertLinesAre("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY");
for (int row = 0; row < 5; row++) { for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) { for (int col = 0; col < 5; col++) {
long s = getStyleAt(row, col); long s = getStyleAt(row, col);
Assert.assertEquals(col, TextStyle.decodeForeColor(s)); Assert.assertEquals(col, TextStyle.decodeForeColor(s));
Assert.assertEquals(row, TextStyle.decodeBackColor(s)); Assert.assertEquals(row, TextStyle.decodeBackColor(s));
} }
@@ -43,7 +43,7 @@ public class CursorAndScreenTest extends TerminalTestCase {
for (int col = 0; col < 5; col++) { for (int col = 0; col < 5; col++) {
int wantedForeground = (row == 1 || row == 2) ? 98 : col; int wantedForeground = (row == 1 || row == 2) ? 98 : col;
int wantedBackground = (row == 1 || row == 2) ? 99 : (row == 0 ? 2 : row); int wantedBackground = (row == 1 || row == 2) ? 99 : (row == 0 ? 2 : row);
long s = getStyleAt(row, col); long s = getStyleAt(row, col);
Assert.assertEquals(wantedForeground, TextStyle.decodeForeColor(s)); Assert.assertEquals(wantedForeground, TextStyle.decodeForeColor(s));
Assert.assertEquals(wantedBackground, TextStyle.decodeBackColor(s)); Assert.assertEquals(wantedBackground, TextStyle.decodeBackColor(s));
} }
@@ -159,11 +159,11 @@ public class CursorAndScreenTest extends TerminalTestCase {
} }
} }
/** /**
* See comments on horizontal tab handling in TerminalEmulator.java. * See comments on horizontal tab handling in TerminalEmulator.java.
* * <p/>
* We do not want to color already written cells when tabbing over them. * We do not want to color already written cells when tabbing over them.
*/ */
public void DISABLED_testHorizontalTabColorsBackground() { public void DISABLED_testHorizontalTabColorsBackground() {
withTerminalSized(10, 3).enterString("\033[48;5;15m").enterString("\t"); withTerminalSized(10, 3).enterString("\033[48;5;15m").enterString("\t");
assertCursorAt(0, 8); assertCursorAt(0, 8);
@@ -214,14 +214,14 @@ public class CursorAndScreenTest extends TerminalTestCase {
" -"); " -");
} }
public void testBackspaceAcrossWrappedLines() { public void testBackspaceAcrossWrappedLines() {
// Backspace should not go to previous line if not auto-wrapped: // Backspace should not go to previous line if not auto-wrapped:
withTerminalSized(3, 3).enterString("hi\r\n\b\byou").assertLinesAre("hi ", "you", " "); withTerminalSized(3, 3).enterString("hi\r\n\b\byou").assertLinesAre("hi ", "you", " ");
// Backspace should go to previous line if auto-wrapped: // Backspace should go to previous line if auto-wrapped:
withTerminalSized(3, 3).enterString("hi y").assertLinesAre("hi ", "y ", " ").enterString("\b\b#").assertLinesAre("hi#", "y ", " "); withTerminalSized(3, 3).enterString("hi y").assertLinesAre("hi ", "y ", " ").enterString("\b\b#").assertLinesAre("hi#", "y ", " ");
// Initial backspace should do nothing: // Initial backspace should do nothing:
withTerminalSized(3, 3).enterString("\b\b\b\bhi").assertLinesAre("hi ", " ", " "); withTerminalSized(3, 3).enterString("\b\b\b\bhi").assertLinesAre("hi ", " ", " ");
} }
public void testCursorSaveRestoreLocation() { public void testCursorSaveRestoreLocation() {
// DEC save/restore // DEC save/restore

View File

@@ -174,18 +174,18 @@ public class KeyHandlerTest extends TestCase {
assertKeysEquals("\033[23;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F11, KeyHandler.KEYMOD_SHIFT, false, false)); assertKeysEquals("\033[23;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F11, KeyHandler.KEYMOD_SHIFT, false, false));
assertKeysEquals("\033[24;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F12, KeyHandler.KEYMOD_SHIFT, false, false)); assertKeysEquals("\033[24;2~", KeyHandler.getCode(KeyEvent.KEYCODE_F12, KeyHandler.KEYMOD_SHIFT, false, false));
assertKeysEquals("0", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_0, 0, false, false)); assertKeysEquals("0", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_0, 0, false, false));
assertKeysEquals("1", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_1, 0, false, false)); assertKeysEquals("1", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_1, 0, false, false));
assertKeysEquals("2", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_2, 0, false, false)); assertKeysEquals("2", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_2, 0, false, false));
assertKeysEquals("3", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_3, 0, false, false)); assertKeysEquals("3", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_3, 0, false, false));
assertKeysEquals("4", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_4, 0, false, false)); assertKeysEquals("4", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_4, 0, false, false));
assertKeysEquals("5", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_5, 0, false, false)); assertKeysEquals("5", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_5, 0, false, false));
assertKeysEquals("6", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_6, 0, false, false)); assertKeysEquals("6", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_6, 0, false, false));
assertKeysEquals("7", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_7, 0, false, false)); assertKeysEquals("7", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_7, 0, false, false));
assertKeysEquals("8", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_8, 0, false, false)); assertKeysEquals("8", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_8, 0, false, false));
assertKeysEquals("9", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_9, 0, false, false)); assertKeysEquals("9", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_9, 0, false, false));
assertKeysEquals(",", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_COMMA, 0, false, false)); assertKeysEquals(",", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_COMMA, 0, false, false));
assertKeysEquals(".", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_DOT, 0, false, false)); assertKeysEquals(".", KeyHandler.getCode(KeyEvent.KEYCODE_NUMPAD_DOT, 0, false, false));
} }
} }

View File

@@ -93,7 +93,7 @@ public class ResizeTest extends TerminalTestCase {
enterString("\033[2J"); enterString("\033[2J");
for (int r = 0; r < rows; r++) { for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
long style = getStyleAt(r, c); long style = getStyleAt(r, c);
assertEquals(119, TextStyle.decodeForeColor(style)); assertEquals(119, TextStyle.decodeForeColor(style));
assertEquals(129, TextStyle.decodeBackColor(style)); assertEquals(129, TextStyle.decodeBackColor(style));
} }
@@ -105,7 +105,7 @@ public class ResizeTest extends TerminalTestCase {
// After resize, screen should still be same color: // After resize, screen should still be same color:
for (int r = 0; r < rows - 2; r++) { for (int r = 0; r < rows - 2; r++) {
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
long style = getStyleAt(r, c); long style = getStyleAt(r, c);
assertEquals(119, TextStyle.decodeForeColor(style)); assertEquals(119, TextStyle.decodeForeColor(style));
assertEquals(129, TextStyle.decodeBackColor(style)); assertEquals(129, TextStyle.decodeBackColor(style));
} }

View File

@@ -107,24 +107,24 @@ public class ScrollRegionTest extends TerminalTestCase {
assertLinesAre("1 ", "2 ", "3 ", "QQ", "YY"); assertLinesAre("1 ", "2 ", "3 ", "QQ", "YY");
} }
/** See https://github.com/termux/termux-app/issues/1340 */ /** See https://github.com/termux/termux-app/issues/1340 */
public void testScrollRegionDoesNotLimitCursorMovement() { public void testScrollRegionDoesNotLimitCursorMovement() {
withTerminalSized(6, 4) withTerminalSized(6, 4)
.enterString("\033[4;7r\033[3;1Haaa\033[Axxx") .enterString("\033[4;7r\033[3;1Haaa\033[Axxx")
.assertLinesAre( .assertLinesAre(
" ", " ",
" xxx", " xxx",
"aaa ", "aaa ",
" " " "
); );
withTerminalSized(6, 4) withTerminalSized(6, 4)
.enterString("\033[1;3r\033[3;1Haaa\033[Bxxx") .enterString("\033[1;3r\033[3;1Haaa\033[Bxxx")
.assertLinesAre( .assertLinesAre(
" ", " ",
" ", " ",
"aaa ", "aaa ",
" xxx" " xxx"
); );
} }
} }

View File

@@ -159,7 +159,7 @@ public class TerminalTest extends TerminalTestCase {
assertEquals(119, mTerminal.mForeColor); assertEquals(119, mTerminal.mForeColor);
assertEquals(129, mTerminal.mBackColor); assertEquals(129, mTerminal.mBackColor);
// Invalid parameter: // Invalid parameter:
enterString("\033[48;8;129m"); enterString("\033[48;8;129m");
assertEquals(119, mTerminal.mForeColor); assertEquals(119, mTerminal.mForeColor);
assertEquals(129, mTerminal.mBackColor); assertEquals(129, mTerminal.mBackColor);
@@ -169,30 +169,30 @@ public class TerminalTest extends TerminalTestCase {
assertEquals(178, mTerminal.mForeColor); assertEquals(178, mTerminal.mForeColor);
assertEquals(179, mTerminal.mBackColor); assertEquals(179, mTerminal.mBackColor);
// 24 bit colors: // 24 bit colors:
enterString(("\033[0m")); // Reset fg and bg colors. enterString(("\033[0m")); // Reset fg and bg colors.
enterString("\033[38;2;255;127;2m"); enterString("\033[38;2;255;127;2m");
int expectedForeground = 0xff000000 | (255 << 16) | (127 << 8) | 2; int expectedForeground = 0xff000000 | (255 << 16) | (127 << 8) | 2;
assertEquals(expectedForeground, mTerminal.mForeColor); assertEquals(expectedForeground, mTerminal.mForeColor);
assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, mTerminal.mBackColor); assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, mTerminal.mBackColor);
enterString("\033[48;2;1;2;254m"); enterString("\033[48;2;1;2;254m");
int expectedBackground = 0xff000000 | (1 << 16) | (2 << 8) | 254; int expectedBackground = 0xff000000 | (1 << 16) | (2 << 8) | 254;
assertEquals(expectedForeground, mTerminal.mForeColor); assertEquals(expectedForeground, mTerminal.mForeColor);
assertEquals(expectedBackground, mTerminal.mBackColor); assertEquals(expectedBackground, mTerminal.mBackColor);
// 24 bit colors, set fg and bg at once: // 24 bit colors, set fg and bg at once:
enterString(("\033[0m")); // Reset fg and bg colors. enterString(("\033[0m")); // Reset fg and bg colors.
assertEquals(TextStyle.COLOR_INDEX_FOREGROUND, mTerminal.mForeColor); assertEquals(TextStyle.COLOR_INDEX_FOREGROUND, mTerminal.mForeColor);
assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, mTerminal.mBackColor); assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, mTerminal.mBackColor);
enterString("\033[38;2;255;127;2;48;2;1;2;254m"); enterString("\033[38;2;255;127;2;48;2;1;2;254m");
assertEquals(expectedForeground, mTerminal.mForeColor); assertEquals(expectedForeground, mTerminal.mForeColor);
assertEquals(expectedBackground, mTerminal.mBackColor); assertEquals(expectedBackground, mTerminal.mBackColor);
// 24 bit colors, invalid input: // 24 bit colors, invalid input:
enterString("\033[38;2;300;127;2;48;2;1;300;254m"); enterString("\033[38;2;300;127;2;48;2;1;300;254m");
assertEquals(expectedForeground, mTerminal.mForeColor); assertEquals(expectedForeground, mTerminal.mForeColor);
assertEquals(expectedBackground, mTerminal.mBackColor); assertEquals(expectedBackground, mTerminal.mBackColor);
} }
public void testBackgroundColorErase() { public void testBackgroundColorErase() {
final int rows = 3; final int rows = 3;
@@ -200,7 +200,7 @@ public class TerminalTest extends TerminalTestCase {
withTerminalSized(cols, rows); withTerminalSized(cols, rows);
for (int r = 0; r < rows; r++) { for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
long style = getStyleAt(r, c); long style = getStyleAt(r, c);
assertEquals(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.decodeForeColor(style)); assertEquals(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.decodeForeColor(style));
assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, TextStyle.decodeBackColor(style)); assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, TextStyle.decodeBackColor(style));
} }
@@ -213,7 +213,7 @@ public class TerminalTest extends TerminalTestCase {
enterString("\033[2J"); enterString("\033[2J");
for (int r = 0; r < rows; r++) { for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
long style = getStyleAt(r, c); long style = getStyleAt(r, c);
assertEquals(119, TextStyle.decodeForeColor(style)); assertEquals(119, TextStyle.decodeForeColor(style));
assertEquals(129, TextStyle.decodeBackColor(style)); assertEquals(129, TextStyle.decodeBackColor(style));
} }
@@ -224,7 +224,7 @@ public class TerminalTest extends TerminalTestCase {
enterString("\033[2L"); enterString("\033[2L");
for (int r = 0; r < rows; r++) { for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) { for (int c = 0; c < cols; c++) {
long style = getStyleAt(r, c); long style = getStyleAt(r, c);
assertEquals((r == 0 || r == 1) ? 139 : 129, TextStyle.decodeBackColor(style)); assertEquals((r == 0 || r == 1) ? 139 : 129, TextStyle.decodeBackColor(style));
} }
} }
@@ -289,9 +289,9 @@ public class TerminalTest extends TerminalTestCase {
withTerminalSized(3, 3).enterString("abc\r ").assertLinesAre(" bc", " ", " ").assertCursorAt(0, 1); withTerminalSized(3, 3).enterString("abc\r ").assertLinesAre(" bc", " ", " ").assertCursorAt(0, 1);
} }
public void testTab() { public void testTab() {
withTerminalSized(11, 2).enterString("01234567890\r\tXX").assertLinesAre("01234567XX0", " "); withTerminalSized(11, 2).enterString("01234567890\r\tXX").assertLinesAre("01234567XX0", " ");
withTerminalSized(11, 2).enterString("01234567890\033[44m\r\tXX").assertLinesAre("01234567XX0", " "); withTerminalSized(11, 2).enterString("01234567890\033[44m\r\tXX").assertLinesAre("01234567XX0", " ");
} }
} }

View File

@@ -18,7 +18,7 @@ public abstract class TerminalTestCase extends TestCase {
public final List<ChangedTitle> titleChanges = new ArrayList<>(); public final List<ChangedTitle> titleChanges = new ArrayList<>();
public final List<String> clipboardPuts = new ArrayList<>(); public final List<String> clipboardPuts = new ArrayList<>();
public int bellsRung = 0; public int bellsRung = 0;
public int colorsChanged = 0; public int colorsChanged = 0;
@Override @Override
public void write(byte[] data, int offset, int count) { public void write(byte[] data, int offset, int count) {
@@ -26,10 +26,10 @@ public abstract class TerminalTestCase extends TestCase {
} }
public String getOutputAndClear() { public String getOutputAndClear() {
String result = new String(baos.toByteArray(), StandardCharsets.UTF_8); String result = new String(baos.toByteArray(), StandardCharsets.UTF_8);
baos.reset(); baos.reset();
return result; return result;
} }
@Override @Override
public void titleChanged(String oldTitle, String newTitle) { public void titleChanged(String oldTitle, String newTitle) {
@@ -46,11 +46,11 @@ public abstract class TerminalTestCase extends TestCase {
bellsRung++; bellsRung++;
} }
@Override @Override
public void onColorsChanged() { public void onColorsChanged() {
colorsChanged++; colorsChanged++;
} }
} }
public TerminalEmulator mTerminal; public TerminalEmulator mTerminal;
public MockTerminalOutput mOutput; public MockTerminalOutput mOutput;

View File

@@ -22,23 +22,23 @@ public class TextStyleTest extends TestCase {
} }
} }
public void testEncoding24Bit() { public void testEncoding24Bit() {
int[] values = {255, 240, 127, 1, 0}; int[] values = {255, 240, 127, 1, 0};
for (int red : values) { for (int red : values) {
for (int green : values) { for (int green : values) {
for (int blue : values) { for (int blue : values) {
int argb = 0xFF000000 | (red << 16) | (green << 8) | blue; int argb = 0xFF000000 | (red << 16) | (green << 8) | blue;
long encoded = TextStyle.encode(argb, 0, 0); long encoded = TextStyle.encode(argb, 0, 0);
assertEquals(argb, TextStyle.decodeForeColor(encoded)); assertEquals(argb, TextStyle.decodeForeColor(encoded));
encoded = TextStyle.encode(0, argb, 0); encoded = TextStyle.encode(0, argb, 0);
assertEquals(argb, TextStyle.decodeBackColor(encoded)); assertEquals(argb, TextStyle.decodeBackColor(encoded));
} }
} }
} }
} }
public void testEncodingCombinations() { public void testEncodingCombinations() {
for (int f1 : ALL_EFFECTS) { for (int f1 : ALL_EFFECTS) {
for (int f2 : ALL_EFFECTS) { for (int f2 : ALL_EFFECTS) {
int combined = f1 | f2; int combined = f1 | f2;
@@ -54,9 +54,9 @@ public class TextStyleTest extends TestCase {
} }
public void testEncodingProtected() { public void testEncodingProtected() {
long encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND, long encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND,
TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH); TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH);
assertEquals(0, (TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED)); assertEquals(0, (TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED));
encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND, encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND,
TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH | TextStyle.CHARACTER_ATTRIBUTE_PROTECTED); TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH | TextStyle.CHARACTER_ATTRIBUTE_PROTECTED);
assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) != 0); assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) != 0);

View File

@@ -15,12 +15,12 @@ public class WcWidthTest extends TestCase {
} }
} }
public void testSomeWidthOne() { public void testSomeWidthOne() {
assertWidthIs(1, 'å'); assertWidthIs(1, 'å');
assertWidthIs(1, 'ä'); assertWidthIs(1, 'ä');
assertWidthIs(1, 'ö'); assertWidthIs(1, 'ö');
assertWidthIs(1, 0x23F2); assertWidthIs(1, 0x23F2);
} }
public void testSomeWide() { public void testSomeWide() {
assertWidthIs(2, ''); assertWidthIs(2, '');
@@ -44,18 +44,18 @@ public class WcWidthTest extends TestCase {
} }
public void testCombining() { public void testCombining() {
assertWidthIs(0, 0x0302); assertWidthIs(0, 0x0302);
assertWidthIs(0, 0x0308); assertWidthIs(0, 0x0308);
assertWidthIs(0, 0xFE0F); assertWidthIs(0, 0xFE0F);
} }
public void testWordJoiner() { public void testWordJoiner() {
// https://en.wikipedia.org/wiki/Word_joiner // https://en.wikipedia.org/wiki/Word_joiner
// The word joiner (WJ) is a code point in Unicode used to separate words when using scripts // The word joiner (WJ) is a code point in Unicode used to separate words when using scripts
// that do not use explicit spacing. It is encoded since Unicode version 3.2 // that do not use explicit spacing. It is encoded since Unicode version 3.2
// (released in 2002) as U+2060 WORD JOINER (HTML &#8288;). // (released in 2002) as U+2060 WORD JOINER (HTML &#8288;).
// The word joiner does not produce any space, and prohibits a line break at its position. // The word joiner does not produce any space, and prohibits a line break at its position.
assertWidthIs(0, 0x2060); assertWidthIs(0, 0x2060);
} }
public void testSofthyphen() { public void testSofthyphen() {
@@ -72,10 +72,10 @@ public class WcWidthTest extends TestCase {
assertWidthIs(1, 0x11A3); assertWidthIs(1, 0x11A3);
} }
public void testEmojis() { public void testEmojis() {
assertWidthIs(2, 0x1F428); // KOALA. assertWidthIs(2, 0x1F428); // KOALA.
assertWidthIs(2, 0x231a); // WATCH. assertWidthIs(2, 0x231a); // WATCH.
assertWidthIs(2, 0x1F643); // UPSIDE-DOWN FACE (Unicode 8). assertWidthIs(2, 0x1F643); // UPSIDE-DOWN FACE (Unicode 8).
} }
} }