package com.termux.terminal; import junit.framework.TestCase; public class WcWidthTest extends TestCase { private static void assertWidthIs(int expectedWidth, int codePoint) { int wcWidth = WcWidth.width(codePoint); assertEquals(expectedWidth, wcWidth); } public void testPrintableAscii() { for (int i = 0x20; i <= 0x7E; i++) { assertWidthIs(1, i); } } public void testSomeWide() { assertWidthIs(2, 'A'); assertWidthIs(2, 'B'); assertWidthIs(2, 'C'); assertWidthIs(2, '中'); assertWidthIs(2, '文'); assertWidthIs(2, 0x679C); assertWidthIs(2, 0x679D); assertWidthIs(2, 0x2070E); assertWidthIs(2, 0x20731); assertWidthIs(1, 0x1F781); } public void testSomeNonWide() { assertWidthIs(1, 0x1D11E); assertWidthIs(1, 0x1D11F); } public void testCombining() { assertWidthIs(0, 0x0302); assertWidthIs(0, 0x0308); assertWidthIs(0, 0x2060); } public void testWatch() { assertWidthIs(1, 0x231a); } public void testSofthyphen() { // http://osdir.com/ml/internationalization.linux/2003-05/msg00006.html: // "Existing implementation practice in terminals is that the SOFT HYPHEN is // a spacing graphical character, and the purpose of my wcwidth() was to // predict the advancement of the cursor position after a string is sent to // a terminal. Hence, I have no choice but to keep wcwidth(SOFT HYPHEN) = 1. // VT100-style terminals do not hyphenate." assertWidthIs(1, 0x00AD); } public void testHangul() { assertWidthIs(2, 0x11A3); } }