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
141 lines (116 loc) · 4.02 KB
/
TestNative.java
File metadata and controls
141 lines (116 loc) · 4.02 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.jsoniter.output;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
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 = new JsonStream(baos, 32);
stream.writeVal("1234567890123456789012345678901234567890");
stream.close();
assertEquals("'1234567890123456789012345678901234567890'".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_big_float() throws IOException {
stream.writeVal(83886082f);
stream.close();
assertEquals("83886080", 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());
}
public void test_big_decimal() throws IOException {
stream.writeVal(new BigDecimal("12.34"));
stream.close();
assertEquals("'12.34'".replace('\'', '"'), baos.toString());
}
public void test_big_integer() throws IOException {
stream.writeVal(new BigInteger("1234"));
stream.close();
assertEquals("'1234'".replace('\'', '"'), baos.toString());
}
public void test_raw() throws IOException {
stream = new JsonStream(baos, 32);
stream.writeRaw("1234567890123456789012345678901234567890");
stream.close();
assertEquals("1234567890123456789012345678901234567890".replace('\'', '"'), baos.toString());
}
}