forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNative.java
More file actions
113 lines (92 loc) · 3 KB
/
TestNative.java
File metadata and controls
113 lines (92 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.jsoniter.output;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class TestNative extends TestCase {
static {
// JsonStream.setMode(EncodingMode.REFLECTION_MODE);
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public void test_string() throws IOException {
stream.writeVal("hello");
stream.close();
assertEquals("'hello'".replace('\'', '"'), baos.toString());
}
public void test_escape() throws IOException {
stream.writeVal("hel\nlo");
stream.close();
assertEquals("'hel\\nlo'".replace('\'', '"'), baos.toString());
}
public void test_utf8() throws IOException {
stream.writeVal("中文");
stream.close();
assertEquals("\"\\u4e2d\\u6587\"", baos.toString());
}
public void test_int() throws IOException {
stream.writeVal(100);
stream.close();
assertEquals("100", baos.toString());
}
public void test_boxed_int() throws IOException {
Object val = Integer.valueOf(100);
stream.writeVal(val);
stream.close();
assertEquals("100", baos.toString());
}
public void test_negative_int() throws IOException {
stream.writeVal(-100);
stream.close();
assertEquals("-100", baos.toString());
}
public void test_small_int() throws IOException {
stream.writeVal(3);
stream.close();
assertEquals("3", baos.toString());
}
public void test_large_int() throws IOException {
stream.writeVal(31415926);
stream.close();
assertEquals("31415926", baos.toString());
}
public void test_long() throws IOException {
stream.writeVal(100L);
stream.close();
assertEquals("100", baos.toString());
}
public void test_negative_long() throws IOException {
stream.writeVal(-100L);
stream.close();
assertEquals("-100", baos.toString());
}
public void test_no_decimal_float() throws IOException {
stream.writeVal(100f);
stream.close();
assertEquals("100", baos.toString());
}
public void test_float2() throws IOException {
stream.writeVal(0.000001f);
stream.close();
assertEquals("0.000001", baos.toString());
}
public void test_float3() throws IOException {
stream.writeVal(0.00001f);
stream.close();
assertEquals("0.00001", baos.toString());
}
public void test_double() throws IOException {
stream.writeVal(0.00001d);
stream.close();
assertEquals("0.00001", baos.toString());
}
public void test_boolean() throws IOException {
stream.writeVal(true);
stream.writeVal(false);
stream.close();
assertEquals("truefalse".replace('\'', '"'), baos.toString());
}
}