OSDN Git Service

remove subversion keyword
[jindolf/JinParser.git] / src / test / java / jp / sourceforge / jindolf / parser / EntityConverterTest.java
1 /*\r
2  * License : The MIT License\r
3  * Copyright(c) 2009 olyutorskii\r
4  */\r
5 \r
6 package jp.sourceforge.jindolf.parser;\r
7 \r
8 import java.util.List;\r
9 import org.junit.After;\r
10 import org.junit.AfterClass;\r
11 import org.junit.Before;\r
12 import org.junit.BeforeClass;\r
13 import org.junit.Test;\r
14 import static org.junit.Assert.*;\r
15 \r
16 /**\r
17  */\r
18 public class EntityConverterTest {\r
19 \r
20     public EntityConverterTest() {\r
21     }\r
22 \r
23     @BeforeClass\r
24     public static void setUpClass() throws Exception{\r
25     }\r
26 \r
27     @AfterClass\r
28     public static void tearDownClass() throws Exception{\r
29     }\r
30 \r
31     @Before\r
32     public void setUp() {\r
33     }\r
34 \r
35     @After\r
36     public void tearDown() {\r
37     }\r
38 \r
39     /**\r
40      * Test of convert method, of class EntityConverter.\r
41      */\r
42     @Test\r
43     public void testConvert(){\r
44         System.out.println("convert");\r
45 \r
46         EntityConverter converter = new EntityConverter();\r
47 \r
48         DecodedContent from;\r
49         DecodedContent result;\r
50 \r
51         from = new DecodedContent();\r
52         from.append("a>b<c"d&e");\r
53         result = converter.convert(from, 0, from.length());\r
54         assertEquals("a>b<c\"d&e", result.toString());\r
55 \r
56         from = new DecodedContent();\r
57         from.append("&gt;&lt;&quot;&amp;");\r
58         result = converter.convert(from, 0, from.length());\r
59         assertEquals("><\"&", result.toString());\r
60 \r
61         from = new DecodedContent();\r
62         from.append("12345");\r
63         result = converter.convert(from, 1, 3);\r
64         assertEquals("23", result.toString());\r
65 \r
66         from = new DecodedContent();\r
67         from.append("12&gt;45");\r
68         result = converter.convert(from, 1, 7);\r
69         assertEquals("2>4", result.toString());\r
70 \r
71         from = new DecodedContent();\r
72         from.append("12&gt;45");\r
73         result = converter.convert(from, 3, 7);\r
74         assertEquals("gt;4", result.toString());\r
75 \r
76         from = new DecodedContent();\r
77         from.append("&amp;gt;");\r
78         result = converter.convert(from, 0, from.length());\r
79         assertEquals("&gt;", result.toString());\r
80 \r
81         from = new DecodedContent();\r
82         from.append("a&gt;b");\r
83         result = converter.convert(from);\r
84         assertEquals("a>b", result.toString());\r
85 \r
86         from = new DecodedContent();\r
87         from.append("a&gt;b");\r
88         from.addDecodeError((byte)0x03);\r
89         from.append("c");\r
90         result = converter.convert(from);\r
91         assertEquals("a>b?c", result.toString());\r
92         assertTrue(result.hasDecodeError());\r
93         List<DecodeErrorInfo> list = result.getDecodeErrorList();\r
94         assertEquals(1, list.size());\r
95         assertEquals((byte)0x03, list.get(0).getRawByte1st());\r
96 \r
97         from = new DecodedContent();\r
98         from.append("");\r
99         result = converter.convert(from, 0, 0);\r
100         assertEquals("", result.toString());\r
101 \r
102         from = new DecodedContent();\r
103         from.append("a\\b");\r
104         result = converter.convert(from, 0, from.length());\r
105         assertEquals("a¥b", result.toString());\r
106 \r
107         from = new DecodedContent();\r
108         from.append("abcde");\r
109         SeqRange range = new SeqRange(1,4);\r
110         result = converter.convert(from, range);\r
111         assertEquals("bcd", result.toString());\r
112 \r
113         return;\r
114     }\r
115 \r
116     /**\r
117      * Test of append method, of class EntityConverter.\r
118      */\r
119     @Test\r
120     public void testAppend(){\r
121         System.out.println("append");\r
122 \r
123         EntityConverter converter = new EntityConverter();\r
124         DecodedContent target;\r
125         DecodedContent from;\r
126         DecodedContent result;\r
127 \r
128         target = new DecodedContent("abc");\r
129         from = new DecodedContent("d&gt;f");\r
130         result = converter.append(target,from);\r
131         assertEquals("abcd>f", result.toString());\r
132 \r
133         target = new DecodedContent("abc");\r
134         from = new DecodedContent("d&gt;fg&lt;i");\r
135         result = converter.append(target, from, 6, 12);\r
136         assertEquals("abcg<i", result.toString());\r
137 \r
138         target = new DecodedContent("abc");\r
139         from = new DecodedContent("d&gt;fg&lt;i");\r
140         result = converter.append(target, from, new SeqRange(6, 12));\r
141         assertEquals("abcg<i", result.toString());\r
142 \r
143         target = new DecodedContent();\r
144         target.append('a');\r
145         target.addDecodeError((byte)0xff);\r
146         target.append('c');\r
147         from = new DecodedContent();\r
148         from.append('d');\r
149         from.addDecodeError((byte)0xfe);\r
150         from.append('f');\r
151         result = converter.append(target, from);\r
152         assertEquals("a?cd?f", result.toString());\r
153         assertTrue(result.hasDecodeError());\r
154         List<DecodeErrorInfo> list = result.getDecodeErrorList();\r
155         assertEquals(2, list.size());\r
156         assertEquals((byte)0xff, list.get(0).getRawByte1st());\r
157         assertEquals((byte)0xfe, list.get(1).getRawByte1st());\r
158         assertEquals(1, list.get(0).getCharPosition());\r
159         assertEquals(4, list.get(1).getCharPosition());\r
160 \r
161         return;\r
162     }\r
163 \r
164 }\r