2 * License : The MIT License
3 * Copyright(c) 2009 olyutorskii
6 package jp.osdn.jindolf.parser;
9 import jp.osdn.jindolf.parser.content.DecodeErrorInfo;
10 import jp.osdn.jindolf.parser.content.DecodedContent;
11 import org.junit.After;
12 import org.junit.AfterClass;
13 import org.junit.Before;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
17 import static org.junit.Assert.*;
21 public class EntityConverterTest {
23 public EntityConverterTest() {
27 public static void setUpClass() throws Exception{
31 public static void tearDownClass() throws Exception{
39 public void tearDown() {
43 * Test of convert method, of class EntityConverter.
46 public void testConvert(){
47 System.out.println("convert");
49 EntityConverter converter = new EntityConverter();
52 DecodedContent result;
54 from = new DecodedContent();
55 from.append("a>b<c"d&e");
56 result = converter.convert(from, 0, from.length());
57 assertEquals("a>b<c\"d&e", result.toString());
59 from = new DecodedContent();
60 from.append("><"&");
61 result = converter.convert(from, 0, from.length());
62 assertEquals("><\"&", result.toString());
64 from = new DecodedContent();
66 result = converter.convert(from, 1, 3);
67 assertEquals("23", result.toString());
69 from = new DecodedContent();
70 from.append("12>45");
71 result = converter.convert(from, 1, 7);
72 assertEquals("2>4", result.toString());
74 from = new DecodedContent();
75 from.append("12>45");
76 result = converter.convert(from, 3, 7);
77 assertEquals("gt;4", result.toString());
79 from = new DecodedContent();
80 from.append("&gt;");
81 result = converter.convert(from, 0, from.length());
82 assertEquals(">", result.toString());
84 from = new DecodedContent();
85 from.append("a>b");
86 result = converter.convert(from);
87 assertEquals("a>b", result.toString());
89 from = new DecodedContent();
90 from.append("a>b");
91 from.addDecodeError((byte)0x03);
93 result = converter.convert(from);
94 assertEquals("a>b?c", result.toString());
95 assertTrue(result.hasDecodeError());
96 List<DecodeErrorInfo> list = result.getDecodeErrorList();
97 assertEquals(1, list.size());
98 assertEquals((byte)0x03, list.get(0).getRawByte1st());
100 from = new DecodedContent();
102 result = converter.convert(from, 0, 0);
103 assertEquals("", result.toString());
105 from = new DecodedContent();
107 result = converter.convert(from, 0, from.length());
108 assertEquals("a¥b", result.toString());
110 from = new DecodedContent();
111 from.append("abcde");
112 SeqRange range = new SeqRange(1,4);
113 result = converter.convert(from, range);
114 assertEquals("bcd", result.toString());
116 from = new DecodedContent();
117 from.append("abcde");
119 converter.convert(from, 4, 1);
121 }catch(IndexOutOfBoundsException e){
125 from = new DecodedContent();
126 from.append("abcde");
128 converter.convert(from, -1, 4);
130 }catch(IndexOutOfBoundsException e){
134 from = new DecodedContent();
135 from.append("abcde");
137 converter.convert(from, 1, 6);
139 }catch(IndexOutOfBoundsException e){
143 from = new DecodedContent();
144 from.append("a\ud83d\udc11b"); // 🐑
145 result = converter.convert(from);
146 assertEquals("a\ud83d\udc11b", result.toString());
148 from = new DecodedContent();
149 from.append("a\ud83d\udc11b"); // 🐑
150 EntityConverter repConverter = new EntityConverter(true);
151 result = repConverter.convert(from);
152 assertEquals("a?b", result.toString());
158 * Test of append method, of class EntityConverter.
161 public void testAppend(){
162 System.out.println("append");
164 EntityConverter converter = new EntityConverter();
165 DecodedContent target;
167 DecodedContent result;
169 target = new DecodedContent("abc");
170 from = new DecodedContent("d>f");
171 result = converter.append(target,from);
172 assertEquals("abcd>f", result.toString());
174 target = new DecodedContent("abc");
175 from = new DecodedContent("d>fg<i");
176 result = converter.append(target, from, 6, 12);
177 assertEquals("abcg<i", result.toString());
179 target = new DecodedContent("abc");
180 from = new DecodedContent("d>fg<i");
181 result = converter.append(target, from, new SeqRange(6, 12));
182 assertEquals("abcg<i", result.toString());
184 target = new DecodedContent();
186 target.addDecodeError((byte)0xff);
188 from = new DecodedContent();
190 from.addDecodeError((byte)0xfe);
192 result = converter.append(target, from);
193 assertEquals("a?cd?f", result.toString());
194 assertTrue(result.hasDecodeError());
195 List<DecodeErrorInfo> list = result.getDecodeErrorList();
196 assertEquals(2, list.size());
197 assertEquals((byte)0xff, list.get(0).getRawByte1st());
198 assertEquals((byte)0xfe, list.get(1).getRawByte1st());
199 assertEquals(1, list.get(0).getCharPosition());
200 assertEquals(4, list.get(1).getCharPosition());