OSDN Git Service

Merge commit '2234b50cfbe7c86237086a3bf4e62397814a390e'
[jindolf/JinParser.git] / src / test / java / jp / sourceforge / jindolf / parser / EntityConverterTest.java
index 457d561..ed5e7e8 100644 (file)
-/*\r
- * Copyright(c) 2009 olyutorskii\r
- * $Id: EntityConverterTest.java 894 2009-11-04 07:26:59Z olyutorskii $\r
- */\r
-\r
-package jp.sourceforge.jindolf.parser;\r
-\r
-import java.util.List;\r
-import org.junit.After;\r
-import org.junit.AfterClass;\r
-import org.junit.Before;\r
-import org.junit.BeforeClass;\r
-import org.junit.Test;\r
-import static org.junit.Assert.*;\r
-\r
-/**\r
- */\r
-public class EntityConverterTest {\r
-\r
-    public EntityConverterTest() {\r
-    }\r
-\r
-    @BeforeClass\r
-    public static void setUpClass() throws Exception{\r
-    }\r
-\r
-    @AfterClass\r
-    public static void tearDownClass() throws Exception{\r
-    }\r
-\r
-    @Before\r
-    public void setUp() {\r
-    }\r
-\r
-    @After\r
-    public void tearDown() {\r
-    }\r
-\r
-    /**\r
-     * Test of convert method, of class EntityConverter.\r
-     */\r
-    @Test\r
-    public void testConvert(){\r
-        System.out.println("convert");\r
-\r
-        EntityConverter converter = new EntityConverter();\r
-\r
-        DecodedContent from;\r
-        DecodedContent result;\r
-\r
-        from = new DecodedContent();\r
-        from.append("a>b<c"d&e");\r
-        result = converter.convert(from, 0, from.length());\r
-        assertEquals("a>b<c\"d&e", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("&gt;&lt;&quot;&amp;");\r
-        result = converter.convert(from, 0, from.length());\r
-        assertEquals("><\"&", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("12345");\r
-        result = converter.convert(from, 1, 3);\r
-        assertEquals("23", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("12&gt;45");\r
-        result = converter.convert(from, 1, 7);\r
-        assertEquals("2>4", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("12&gt;45");\r
-        result = converter.convert(from, 3, 7);\r
-        assertEquals("gt;4", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("&amp;gt;");\r
-        result = converter.convert(from, 0, from.length());\r
-        assertEquals("&gt;", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("a&gt;b");\r
-        result = converter.convert(from);\r
-        assertEquals("a>b", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("a&gt;b");\r
-        from.addDecodeError((byte)0x03);\r
-        from.append("c");\r
-        result = converter.convert(from);\r
-        assertEquals("a>b?c", result.toString());\r
-        assertTrue(result.hasDecodeError());\r
-        List<DecodeErrorInfo> list = result.getDecodeErrorList();\r
-        assertEquals(1, list.size());\r
-        assertEquals((byte)0x03, list.get(0).getRawByte1st());\r
-\r
-        from = new DecodedContent();\r
-        from.append("");\r
-        result = converter.convert(from, 0, 0);\r
-        assertEquals("", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("a\\b");\r
-        result = converter.convert(from, 0, from.length());\r
-        assertEquals("a¥b", result.toString());\r
-\r
-        from = new DecodedContent();\r
-        from.append("abcde");\r
-        SeqRange range = new SeqRange(1,4);\r
-        result = converter.convert(from, range);\r
-        assertEquals("bcd", result.toString());\r
-\r
-        return;\r
-    }\r
-\r
-    /**\r
-     * Test of append method, of class EntityConverter.\r
-     */\r
-    @Test\r
-    public void testAppend(){\r
-        System.out.println("append");\r
-\r
-        EntityConverter converter = new EntityConverter();\r
-        DecodedContent target;\r
-        DecodedContent from;\r
-        DecodedContent result;\r
-\r
-        target = new DecodedContent("abc");\r
-        from = new DecodedContent("d&gt;f");\r
-        result = converter.append(target,from);\r
-        assertEquals("abcd>f", result.toString());\r
-\r
-        target = new DecodedContent("abc");\r
-        from = new DecodedContent("d&gt;fg&lt;i");\r
-        result = converter.append(target, from, 6, 12);\r
-        assertEquals("abcg<i", result.toString());\r
-\r
-        target = new DecodedContent("abc");\r
-        from = new DecodedContent("d&gt;fg&lt;i");\r
-        result = converter.append(target, from, new SeqRange(6, 12));\r
-        assertEquals("abcg<i", result.toString());\r
-\r
-        target = new DecodedContent();\r
-        target.append('a');\r
-        target.addDecodeError((byte)0xff);\r
-        target.append('c');\r
-        from = new DecodedContent();\r
-        from.append('d');\r
-        from.addDecodeError((byte)0xfe);\r
-        from.append('f');\r
-        result = converter.append(target, from);\r
-        assertEquals("a?cd?f", result.toString());\r
-        assertTrue(result.hasDecodeError());\r
-        List<DecodeErrorInfo> list = result.getDecodeErrorList();\r
-        assertEquals(2, list.size());\r
-        assertEquals((byte)0xff, list.get(0).getRawByte1st());\r
-        assertEquals((byte)0xfe, list.get(1).getRawByte1st());\r
-        assertEquals(1, list.get(0).getCharPosition());\r
-        assertEquals(4, list.get(1).getCharPosition());\r
-\r
-        return;\r
-    }\r
-\r
-}\r
+/*
+ * License : The MIT License
+ * Copyright(c) 2009 olyutorskii
+ */
+
+package jp.sourceforge.jindolf.parser;
+
+import java.util.List;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ */
+public class EntityConverterTest {
+
+    public EntityConverterTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception{
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception{
+    }
+
+    @Before
+    public void setUp() {
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of convert method, of class EntityConverter.
+     */
+    @Test
+    public void testConvert(){
+        System.out.println("convert");
+
+        EntityConverter converter = new EntityConverter();
+
+        DecodedContent from;
+        DecodedContent result;
+
+        from = new DecodedContent();
+        from.append("a&gt;b&lt;c&quot;d&amp;e");
+        result = converter.convert(from, 0, from.length());
+        assertEquals("a>b<c\"d&e", result.toString());
+
+        from = new DecodedContent();
+        from.append("&gt;&lt;&quot;&amp;");
+        result = converter.convert(from, 0, from.length());
+        assertEquals("><\"&", result.toString());
+
+        from = new DecodedContent();
+        from.append("12345");
+        result = converter.convert(from, 1, 3);
+        assertEquals("23", result.toString());
+
+        from = new DecodedContent();
+        from.append("12&gt;45");
+        result = converter.convert(from, 1, 7);
+        assertEquals("2>4", result.toString());
+
+        from = new DecodedContent();
+        from.append("12&gt;45");
+        result = converter.convert(from, 3, 7);
+        assertEquals("gt;4", result.toString());
+
+        from = new DecodedContent();
+        from.append("&amp;gt;");
+        result = converter.convert(from, 0, from.length());
+        assertEquals("&gt;", result.toString());
+
+        from = new DecodedContent();
+        from.append("a&gt;b");
+        result = converter.convert(from);
+        assertEquals("a>b", result.toString());
+
+        from = new DecodedContent();
+        from.append("a&gt;b");
+        from.addDecodeError((byte)0x03);
+        from.append("c");
+        result = converter.convert(from);
+        assertEquals("a>b?c", result.toString());
+        assertTrue(result.hasDecodeError());
+        List<DecodeErrorInfo> list = result.getDecodeErrorList();
+        assertEquals(1, list.size());
+        assertEquals((byte)0x03, list.get(0).getRawByte1st());
+
+        from = new DecodedContent();
+        from.append("");
+        result = converter.convert(from, 0, 0);
+        assertEquals("", result.toString());
+
+        from = new DecodedContent();
+        from.append("a\\b");
+        result = converter.convert(from, 0, from.length());
+        assertEquals("a¥b", result.toString());
+
+        from = new DecodedContent();
+        from.append("abcde");
+        SeqRange range = new SeqRange(1,4);
+        result = converter.convert(from, range);
+        assertEquals("bcd", result.toString());
+
+        from = new DecodedContent();
+        from.append("abcde");
+        try{
+            converter.convert(from, 4, 1);
+            fail();
+        }catch(IndexOutOfBoundsException e){
+            // OK
+        }
+
+        from = new DecodedContent();
+        from.append("abcde");
+        try{
+            converter.convert(from, -1, 4);
+            fail();
+        }catch(IndexOutOfBoundsException e){
+            // OK
+        }
+
+        from = new DecodedContent();
+        from.append("abcde");
+        try{
+            converter.convert(from, 1, 6);
+            fail();
+        }catch(IndexOutOfBoundsException e){
+            // OK
+        }
+
+        from = new DecodedContent();
+        from.append("a\ud83d\udc11b"); // 🐑
+        result = converter.convert(from);
+        assertEquals("a\ud83d\udc11b", result.toString());
+
+        from = new DecodedContent();
+        from.append("a\ud83d\udc11b"); // 🐑
+        EntityConverter repConverter = new EntityConverter(true);
+        result = repConverter.convert(from);
+        assertEquals("a?b", result.toString());
+
+        return;
+    }
+
+    /**
+     * Test of append method, of class EntityConverter.
+     */
+    @Test
+    public void testAppend(){
+        System.out.println("append");
+
+        EntityConverter converter = new EntityConverter();
+        DecodedContent target;
+        DecodedContent from;
+        DecodedContent result;
+
+        target = new DecodedContent("abc");
+        from = new DecodedContent("d&gt;f");
+        result = converter.append(target,from);
+        assertEquals("abcd>f", result.toString());
+
+        target = new DecodedContent("abc");
+        from = new DecodedContent("d&gt;fg&lt;i");
+        result = converter.append(target, from, 6, 12);
+        assertEquals("abcg<i", result.toString());
+
+        target = new DecodedContent("abc");
+        from = new DecodedContent("d&gt;fg&lt;i");
+        result = converter.append(target, from, new SeqRange(6, 12));
+        assertEquals("abcg<i", result.toString());
+
+        target = new DecodedContent();
+        target.append('a');
+        target.addDecodeError((byte)0xff);
+        target.append('c');
+        from = new DecodedContent();
+        from.append('d');
+        from.addDecodeError((byte)0xfe);
+        from.append('f');
+        result = converter.append(target, from);
+        assertEquals("a?cd?f", result.toString());
+        assertTrue(result.hasDecodeError());
+        List<DecodeErrorInfo> list = result.getDecodeErrorList();
+        assertEquals(2, list.size());
+        assertEquals((byte)0xff, list.get(0).getRawByte1st());
+        assertEquals((byte)0xfe, list.get(1).getRawByte1st());
+        assertEquals(1, list.get(0).getCharPosition());
+        assertEquals(4, list.get(1).getCharPosition());
+
+        return;
+    }
+
+}