@@ -31,88 +31,84 @@ public class JSONReadWriteTest extends TestCase {
3131
3232 public void testReadWriteSimple () throws Exception {
3333
34- Object myRet ;
35- String myJson ;
36-
37- // simple string
38- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("blah" ));
39- assertEquals ("blah" , myRet );
40-
41- // simple int
42- myRet = new JSONReader ().read (myJson = new JSONWriter ().write (1 ));
43- assertEquals (1 , myRet );
44-
45- // string with double quotes
46- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t1-blah\" blah" ));
47- assertEquals ("t1-blah\" blah" , myRet );
48- // string with single quotes
49- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t2-blah'blah" ));
50- assertEquals ("t2-blah'blah" , myRet );
51- // string with two double quotes
52- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t3-blah\" n\" blah" ));
53- assertEquals ("t3-blah\" n\" blah" , myRet );
54- // string with two single quotes
55- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t4-blah'n'blah" ));
56- assertEquals ("t4-blah'n'blah" , myRet );
57- // string with a single and a double quote
58- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t4-blah'n\" blah" ));
59- assertEquals ("t4-blah'n\" blah" , myRet );
60-
61- // UTF-8 character
62- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("smile \u9786 " ));
63- // System.out.println("JSON: "+myJson);
64- // System.out.println("JSON: "+myRet);
65- assertEquals ("smile \u9786 " , myRet );
66-
67- // null byte
68- myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("smile \u0000 " ));
69- // System.out.println("JSON: "+myJson);
70- // System.out.println("JSON: "+myRet);
71- assertEquals ("smile \u0000 " , myRet );
34+ Object myRet ;
35+ String myJson ;
36+
37+ // simple string
38+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("blah" ));
39+ assertEquals ("blah" , myRet );
40+
41+ // simple int
42+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write (1 ));
43+ assertEquals (1 , myRet );
44+
45+ // string with double quotes
46+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t1-blah\" blah" ));
47+ assertEquals ("t1-blah\" blah" , myRet );
48+ // string with single quotes
49+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t2-blah'blah" ));
50+ assertEquals ("t2-blah'blah" , myRet );
51+ // string with two double quotes
52+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t3-blah\" n\" blah" ));
53+ assertEquals ("t3-blah\" n\" blah" , myRet );
54+ // string with two single quotes
55+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t4-blah'n'blah" ));
56+ assertEquals ("t4-blah'n'blah" , myRet );
57+ // string with a single and a double quote
58+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("t4-blah'n\" blah" ));
59+ assertEquals ("t4-blah'n\" blah" , myRet );
60+
61+ // UTF-8 character
62+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("smile \u9786 " ));
63+ assertEquals ("smile \u9786 " , myRet );
64+
65+ // null byte
66+ myRet = new JSONReader ().read (myJson = new JSONWriter ().write ("smile \u0000 " ));
67+ assertEquals ("smile \u0000 " , myRet );
7268
7369 }
7470
7571 public void testMoreComplicated () throws Exception {
7672
77- String v , s ;
78- Object t ;
73+ String v , s ;
74+ Object t ;
7975
80- s = "[\" foo\" ,{\" bar\" :[\" baz\" ,null,1.0,2]}]" ;
81- v = new JSONWriter ().write (new JSONReader ().read (s ));
82- assertEquals (s , v );
76+ s = "[\" foo\" ,{\" bar\" :[\" baz\" ,null,1.0,2]}]" ;
77+ v = new JSONWriter ().write (new JSONReader ().read (s ));
78+ assertEquals (s , v );
8379
84- s = "[\" foo\" ,{\" bar\" :[\" b\\ \" az\" ,null,1.0,2]}]" ;
85- t = new JSONReader ().read (s );
86- v = new JSONWriter ().write (t );
87- assertEquals (s , v );
80+ s = "[\" foo\" ,{\" bar\" :[\" b\\ \" az\" ,null,1.0,2]}]" ;
81+ t = new JSONReader ().read (s );
82+ v = new JSONWriter ().write (t );
83+ assertEquals (s , v );
8884
89- s = "[\" foo\" ,{\" bar\" :[\" b'az\" ,null,1.0,2]}]" ;
90- v = new JSONWriter ().write (new JSONReader ().read (s ));
91- assertEquals (s , v );
85+ s = "[\" foo\" ,{\" bar\" :[\" b'az\" ,null,1.0,2]}]" ;
86+ v = new JSONWriter ().write (new JSONReader ().read (s ));
87+ assertEquals (s , v );
9288
93- s = "[\" foo\" ,{\" bar\" :[\" b'a'z\" ,null,1.0,2]}]" ;
94- v = new JSONWriter ().write (new JSONReader ().read (s ));
95- assertEquals (s , v );
89+ s = "[\" foo\" ,{\" bar\" :[\" b'a'z\" ,null,1.0,2]}]" ;
90+ v = new JSONWriter ().write (new JSONReader ().read (s ));
91+ assertEquals (s , v );
9692
97- s = "[\" foo\" ,{\" bar\" :[\" b\\ \" a\\ \" z\" ,null,1.0,2]}]" ;
98- v = new JSONWriter ().write (new JSONReader ().read (s ));
99- assertEquals (s , v );
93+ s = "[\" foo\" ,{\" bar\" :[\" b\\ \" a\\ \" z\" ,null,1.0,2]}]" ;
94+ v = new JSONWriter ().write (new JSONReader ().read (s ));
95+ assertEquals (s , v );
10096
10197 }
10298
10399 public void testBadJSON () throws Exception {
104100
105- try {
106- new JSONReader ().read ("[\" foo\" ,{\" bar\" :[\" b\" az\" ,null,1.0,2]}]" );
107- fail ("Should not have parsed" );
108- }
109- catch (IllegalStateException e ) {}
110-
111- try {
112- new JSONReader ().read ("[\" foo\" ,{\" bar\" :[\" b\" a\" z\" ,null,1.0,2]}]" );
113- fail ("Should not have parsed" );
114- }
115- catch (IllegalStateException e ) {}
101+ try {
102+ new JSONReader ().read ("[\" foo\" ,{\" bar\" :[\" b\" az\" ,null,1.0,2]}]" );
103+ fail ("Should not have parsed" );
104+ }
105+ catch (IllegalStateException e ) {}
106+
107+ try {
108+ new JSONReader ().read ("[\" foo\" ,{\" bar\" :[\" b\" a\" z\" ,null,1.0,2]}]" );
109+ fail ("Should not have parsed" );
110+ }
111+ catch (IllegalStateException e ) {}
116112
117113 }
118114
0 commit comments