forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDirect.java
More file actions
55 lines (45 loc) · 1.5 KB
/
TestDirect.java
File metadata and controls
55 lines (45 loc) · 1.5 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
package com.jsoniter.output;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class TestDirect extends TestCase {
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_int() throws IOException {
stream.writeVal(100);
stream.close();
assertEquals("100".replace('\'', '"'), baos.toString());
}
public void test_boolean() throws IOException {
stream.writeVal(true);
stream.writeVal(false);
stream.close();
assertEquals("truefalse".replace('\'', '"'), baos.toString());
}
public void test_array() throws IOException {
stream.startArray();
stream.writeVal("hello");
stream.writeMore();
stream.endArray();
stream.close();
assertEquals("['hello']".replace('\'', '"'), baos.toString());
}
public void test_object() throws IOException {
stream.startObject();
stream.writeField("hello");
stream.writeVal("world");
stream.writeMore();
stream.endObject();
stream.close();
assertEquals("{'hello':'world'}".replace('\'', '"'), baos.toString());
}
}