forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestStreamBuffer.java
More file actions
68 lines (59 loc) · 2.39 KB
/
TestStreamBuffer.java
File metadata and controls
68 lines (59 loc) · 2.39 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
package com.jsoniter.output;
import com.jsoniter.spi.Config;
import com.jsoniter.spi.JsoniterSpi;
import junit.framework.TestCase;
import java.io.IOException;
public class TestStreamBuffer extends TestCase {
public void test_write_string() throws IOException {
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.writeVal("01234567");
jsonStream.writeVal("01234567");
jsonStream.writeVal("012345678");
jsonStream.writeVal("");
assertEquals(33, jsonStream.buffer().len());
}
public void test_write_raw() throws IOException {
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.writeRaw("0123456789");
jsonStream.writeRaw("0123456789");
jsonStream.writeRaw("0123456789");
jsonStream.writeRaw("0123456789");
assertEquals(40, jsonStream.buffer().len());
}
public void test_write_bytes() throws IOException {
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.write("0123456789".getBytes());
jsonStream.write("0123456789".getBytes());
jsonStream.write("0123456789".getBytes());
jsonStream.write("0123456789".getBytes());
assertEquals(40, jsonStream.buffer().len());
}
public void test_write_indention() throws IOException {
Config oldConfig = JsoniterSpi.getCurrentConfig();
try {
JsoniterSpi.setCurrentConfig(new Config.Builder().indentionStep(32).build());
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.writeArrayStart();
jsonStream.writeIndention();
assertEquals(34, jsonStream.buffer().len());
} finally {
JsoniterSpi.setCurrentConfig(oldConfig);
}
}
public void test_write_int() throws IOException {
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.writeVal(123456789);
jsonStream.writeVal(123456789);
jsonStream.writeVal(123456789);
jsonStream.writeVal(123456789);
assertEquals(36, jsonStream.buffer().len());
}
public void test_write_long() throws IOException {
JsonStream jsonStream = new JsonStream(null, 32);
jsonStream.writeVal(123456789L);
jsonStream.writeVal(123456789L);
jsonStream.writeVal(123456789L);
jsonStream.writeVal(123456789L);
assertEquals(36, jsonStream.buffer().len());
}
}