/**
 * 
 */
package me.xuender.unidecode;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.Test;

/**
 * @author <a href="mailto:xuender@gmail.com">ender</a>
 * 
 */
public class UnidecodeTest {

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * Test method for
	 * {@link me.xuender.unidecode.Unidecode#decode(java.lang.String)}.
	 */
	@Test
	public void testDecode() {
		assertEquals("hello world", "Hello world.",
				Unidecode.decode("Hello world."));
		assertEquals("南无阿弥陀佛", "Nan Wu A Mi Tuo Fo", Unidecode.decode("南无阿弥陀佛"));
		assertEquals("Κνωσός", "Knosos", Unidecode.decode("Κνωσός"));
		assertEquals("あみだにょらい", "amidaniyorai", Unidecode.decode("あみだにょらい"));
	}

	/**
	 * Test method for
	 * {@link me.xuender.unidecode.Unidecode#decode(java.lang.String)}.
	 */
	@Test
	public void testDecodeException() {
		assertEquals("", "", Unidecode.decode(""));
		assertEquals("NULL", "", Unidecode.decode(null));
	}

	/**
	 * Test method for
	 * {@link me.xuender.unidecode.Unidecode#initials(java.lang.String)}.
	 */
	@Test
	public void testInitials() {
		assertEquals("hello world", "Hw", Unidecode.initials("Hello world."));
		assertEquals("南无阿弥陀佛", "NWAMTF", Unidecode.initials("南无阿弥陀佛"));
		assertEquals("Κνωσός", "K", Unidecode.initials("Κνωσός"));
		assertEquals("あみだにょらい", "a", Unidecode.initials("あみだにょらい"));
		assertEquals("enter", "XXGN\nQZQC\n\rTZHL\tSSC",
				Unidecode.initials("小小姑娘\n清早起床\n\r提着花篮\t上市场。"));
	}

	/**
	 * Test method for
	 * {@link me.xuender.unidecode.Unidecode#initials(java.lang.String)}.
	 */
	@Test
	public void testInitialsException() {
		assertEquals("", "", Unidecode.initials(""));
		assertEquals("NULL", "", Unidecode.initials(null));
	}

	/**
	 * 2013-09-06 17:57
	 * 
	 * 你好，最近在项目中使用Unidecode，把用户名转拼音后的声母取出来，发现在转换“一”这个字的时候结果有问题 String pinyin =
	 * Unidecode.decode("一条会走路的鱼"); System.out.print(pinyin.charAt(0)); 输出结果为：[
	 * 怎么办？
	 */
	@Test
	public void testDecodeYi() {
		assertEquals("何清宝提出的bug", "Yi Tiao Hui Zou Lu De Yu",
				Unidecode.decode("一条会走路的鱼"));
	}

	/**
	 * 检查全部汉字是否还有[开头的情况
	 */
	@Test
	public void testAll() {
		int a = (int) (4 * Math.pow(16, 3) + 14 * Math.pow(16, 2)); // 汉字ASCII码最小值
		int b = (int) (9 * Math.pow(16, 3) + 15 * Math.pow(16, 2) + 10 * Math
				.pow(16, 1)) + 5; // 汉字ASCII码最大值
		for (int i = a; i <= b; i++) {
			assertNotEquals("不是[开头", "[", Unidecode.decode((char) i + "")
					.charAt(0));
		}
	}

	/**
	 * ArrayIndexOutOfBound exception
	 * 
	 * Schweigi opened this issue
	 * 
	 * If decode() is used with e.g. an emoticon character there is a
	 * ArrayIndexOutOfBound exception thrown.
	 * 
	 * Example text: http://www.scarfboy.com/coding/unicode-tool?s=U%2b1F61C
	 * 
	 * String[] ret = cache[section]; (Line: 63)
	 * 
	 * The reason is that on Line 52 int section = codepoint >> 8; the section
	 * will be bigger than 255 and therefore out of the cache area.
	 * 
	 * In my opinion there are two solution:
	 * 
	 * Either the cache is made bigger to contain all value up to 0xEFFFF or
	 * Characters with a value bigger (> 0xFFFF) than the cache should not be
	 * cached.
	 */
	@Test
	public void testIssues2() {
		assertEquals("", Unidecode.decode("😜"));
		assertEquals("H", Unidecode.decode("Ｈ"));
	}
}
@@ -3296,9 +3296,408 @@
 %22));%0A%09%7D%0A
+    /**%0A     * %E4%BF%AE%E6%94%B9%E4%B8%87%E7%9A%84%E6%8B%BC%E9%9F%B3%E7%BF%BB%E8%AF%91%E9%94%99%E8%AF%AF%E7%9A%84%E9%97%AE%E9%A2%98 %E4%B8%87%E7%9A%84%E6%8B%BC%E9%9F%B3%E6%98%AFwan%EF%BC%8C%E4%B8%8D%E6%98%AFmo%0A     */%0A    @Test%0A    public void testWan()%7B%0A        assertEquals(%22W%22, Unidecode.initials(%22%E4%B8%87%22));%0A        assertEquals(%22Wan%22, Unidecode.decode(%22%E4%B8%87%22));%0A    %7D%0A    /**%0A     * %E6%B7%BB%E5%8A%A0%5Cu4e06 %E4%B8%86%E7%9A%84%E8%AF%BB%E9%9F%B3%EF%BC%8C%E5%8F%82%E8%80%83unicode.org%E7%9A%84%E8%B5%84%E6%96%99%0A     */%0A    @Test%0A    public void testHan()%7B%0A        assertEquals(%22H%22, Unidecode.initials(%22%E4%B8%86%22));%0A        assertEquals(%22Han%22, Unidecode.decode(%22%E4%B8%86%22));%0A    %7D%0A
 %7D

fix #5 add test