@@ -31,88 +31,84 @@ public class JSONReadWriteTest extends TestCase {
31
31
32
32
public void testReadWriteSimple () throws Exception {
33
33
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 );
72
68
73
69
}
74
70
75
71
public void testMoreComplicated () throws Exception {
76
72
77
- String v , s ;
78
- Object t ;
73
+ String v , s ;
74
+ Object t ;
79
75
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 );
83
79
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 );
88
84
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 );
92
88
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 );
96
92
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 );
100
96
101
97
}
102
98
103
99
public void testBadJSON () throws Exception {
104
100
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 ) {}
116
112
117
113
}
118
114
0 commit comments