OSDN Git Service

topic/jiocema とマージ
[jindolf/JinParser.git] / src / test / java / jp / osdn / jindolf / parser / content / ShiftJisTest.java
1 /*
2  * License : The MIT License
3  * Copyright(c) 2009 olyutorskii
4  */
5
6 package jp.osdn.jindolf.parser.content;
7
8 import java.io.UnsupportedEncodingException;
9 import org.junit.After;
10 import org.junit.AfterClass;
11 import org.junit.Before;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14
15 import static org.junit.Assert.*;
16
17 /**
18  */
19 public class ShiftJisTest {
20
21     public ShiftJisTest() {
22     }
23
24     @BeforeClass
25     public static void setUpClass() throws Exception{
26     }
27
28     @AfterClass
29     public static void tearDownClass() throws Exception{
30     }
31
32     @Before
33     public void setUp() {
34     }
35
36     @After
37     public void tearDown() {
38     }
39
40     /**
41      * Test of isShiftJIS1stByte method, of class ShiftJis.
42      */
43     @Test
44     public void testIsShiftJIS1stByte(){
45         System.out.println("isShiftJIS1stByte");
46
47         for(int ival=0x00; ival <= 0x80; ival++){
48             byte bval = (byte)ival;
49             assertFalse(ShiftJis.isShiftJIS1stByte(bval));
50         }
51
52         for(int ival=0x81; ival <= 0x9f; ival++){
53             byte bval = (byte)ival;
54             assertTrue(ShiftJis.isShiftJIS1stByte(bval));
55         }
56
57         for(int ival=0xa0; ival <= 0xdf; ival++){
58             byte bval = (byte)ival;
59             assertFalse(ShiftJis.isShiftJIS1stByte(bval));
60         }
61
62         for(int ival=0xe0; ival <= 0xfc; ival++){
63             byte bval = (byte)ival;
64             assertTrue(ShiftJis.isShiftJIS1stByte(bval));
65         }
66
67         for(int ival=0xfd; ival <= 0xff; ival++){
68             byte bval = (byte)ival;
69             assertFalse(ShiftJis.isShiftJIS1stByte(bval));
70         }
71
72         byte[] array;
73         try{
74             // 全角スペース
75             array = "\u3000".getBytes("Shift_JIS");
76             assertTrue(ShiftJis.isShiftJIS1stByte(array[0]));
77             // 「熙」
78             array = "\u7199".getBytes("Shift_JIS");
79             assertTrue(ShiftJis.isShiftJIS1stByte(array[0]));
80             // 「"」
81             array = "\uff02".getBytes("Windows-31J");
82             assertTrue(ShiftJis.isShiftJIS1stByte(array[0]));
83         }catch(UnsupportedEncodingException e){
84             fail();
85         }
86
87         return;
88     }
89
90     /**
91      * Test of isShiftJIS2ndByte method, of class ShiftJis.
92      */
93     @Test
94     public void testIsShiftJIS2ndByte(){
95         System.out.println("isShiftJIS2ndByte");
96
97         for(int ival=0x00; ival <= 0x3f; ival++){
98             byte bval = (byte)ival;
99             assertFalse(ShiftJis.isShiftJIS2ndByte(bval));
100         }
101
102         for(int ival=0x40; ival <= 0x7e; ival++){
103             byte bval = (byte)ival;
104             assertTrue(ShiftJis.isShiftJIS2ndByte(bval));
105         }
106
107         for(int ival=0x7f; ival <= 0x7f; ival++){
108             byte bval = (byte)ival;
109             assertFalse(ShiftJis.isShiftJIS2ndByte(bval));
110         }
111
112         for(int ival=0x80; ival <= 0xfc; ival++){
113             byte bval = (byte)ival;
114             assertTrue(ShiftJis.isShiftJIS2ndByte(bval));
115         }
116
117         for(int ival=0xfd; ival <= 0xff; ival++){
118             byte bval = (byte)ival;
119             assertFalse(ShiftJis.isShiftJIS2ndByte(bval));
120         }
121
122         byte[] array;
123         try{
124             // 全角スペース
125             array = "\u3000".getBytes("Shift_JIS");
126             assertTrue(ShiftJis.isShiftJIS2ndByte(array[1]));
127             // 「熙」
128             array = "\u7199".getBytes("Shift_JIS");
129             assertTrue(ShiftJis.isShiftJIS2ndByte(array[1]));
130             // 「"」
131             array = "\uff02".getBytes("Windows-31J");
132             assertTrue(ShiftJis.isShiftJIS2ndByte(array[1]));
133         }catch(UnsupportedEncodingException e){
134             fail();
135         }
136
137         return;
138     }
139
140     /**
141      * Test of isShiftJIS method, of class ShiftJis.
142      */
143     @Test
144     public void testIsShiftJIS(){
145         System.out.println("isShiftJIS");
146
147         byte[] array;
148         try{
149             // 全角スペース
150             array = "\u3000".getBytes("Shift_JIS");
151             assertTrue(ShiftJis.isShiftJIS(array[0], array[1]));
152             // 「熙」
153             array = "\u7199".getBytes("Shift_JIS");
154             assertTrue(ShiftJis.isShiftJIS(array[0], array[1]));
155             // 「"」
156             array = "\uff02".getBytes("Windows-31J");
157             assertTrue(ShiftJis.isShiftJIS(array[0], array[1]));
158         }catch(UnsupportedEncodingException e){
159             fail();
160         }
161
162         return;
163     }
164
165 }