forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSkip.java
More file actions
56 lines (49 loc) · 1.8 KB
/
TestSkip.java
File metadata and controls
56 lines (49 loc) · 1.8 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
package com.jsoniter;
import com.jsoniter.Jsoniter;
import junit.framework.TestCase;
import java.io.IOException;
public class TestSkip extends TestCase {
public void test_skip_number() throws IOException {
Jsoniter iter = Jsoniter.parse("[1,2]");
assertTrue(iter.readArray());
iter.skip();
assertTrue(iter.readArray());
assertEquals(2, iter.readUnsignedInt());
assertFalse(iter.readArray());
}
public void test_skip_string() throws IOException {
Jsoniter iter = Jsoniter.parse("['hello',2]".replace('\'', '"'));
assertTrue(iter.readArray());
iter.skip();
assertTrue(iter.readArray());
assertEquals(2, iter.readUnsignedInt());
assertFalse(iter.readArray());
}
public void test_skip_object() throws IOException {
Jsoniter iter = Jsoniter.parse("[{'hello': {'world': 'a'}},2]".replace('\'', '"'));
assertTrue(iter.readArray());
iter.skip();
assertTrue(iter.readArray());
assertEquals(2, iter.readUnsignedInt());
assertFalse(iter.readArray());
}
public void test_find_string_end() throws IOException {
Jsoniter iter = Jsoniter.parse("\"a");
assertEquals(1, iter.findStringEnd());
}
// public void test_large_file() throws IOException {
// for (int i = 0; i < 100; i++) {
// FileInputStream fileInputStream = new FileInputStream("/tmp/large-file.json");
// Jsoniter iter = Jsoniter.parse(fileInputStream, 4096);
// int total = 0;
// while (iter.readArray()) {
// iter.skip();
// total++;
// }
// if (total != 11351) {
// throw new RuntimeException();
// }
// fileInputStream.close();
// }
// }
}