@@ -19,6 +19,31 @@ class ArrayParserTests: XCTestCase {
19
19
XCTAssertEqual ( result, [ . bool( true ) ] )
20
20
}
21
21
22
+ func testNestedArrays( ) throws {
23
+ var parser = JSONParserImpl ( bytes: [ UInt8] ( " [[]] " . utf8) )
24
+ let _ = try XCTUnwrap ( parser. reader. read ( ) )
25
+
26
+ let result = try parser. parseArray ( )
27
+ XCTAssertEqual ( result, [ . array( [ ] ) ] )
28
+ }
29
+
30
+ func testHighlyNestedArray( ) throws {
31
+ // test 512 should succeed
32
+ let passingString = String ( repeating: " [ " , count: 512 ) + String( repeating: " ] " , count: 512 )
33
+ _ = try JSONParser ( ) . parse ( bytes: [ UInt8] ( passingString. utf8) )
34
+
35
+ let failingString = String ( repeating: " [ " , count: 513 )
36
+ do {
37
+ _ = try JSONParser ( ) . parse ( bytes: [ UInt8] ( failingString. utf8) )
38
+ }
39
+ catch JSONError . tooManyNestedArraysOrDictionaries( characterIndex: 512 ) {
40
+ //expected case
41
+ }
42
+ catch {
43
+ XCTFail ( " Unexpected error: \( error) " )
44
+ }
45
+ }
46
+
22
47
func testSimpleTrueAndStringArray( ) throws {
23
48
var parser = JSONParserImpl ( bytes: [ UInt8] ( #"[ true , "hello" ]"# . utf8) )
24
49
let _ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -27,7 +52,7 @@ class ArrayParserTests: XCTestCase {
27
52
XCTAssertEqual ( result, [ . bool( true ) , . string( " hello " ) ] )
28
53
}
29
54
30
- func testCommaBeforeEnd( ) throws {
55
+ func testCommaBeforeEnd( ) {
31
56
do {
32
57
var parser = JSONParserImpl ( bytes: [ UInt8] ( " [ true , ] " . utf8) )
33
58
_ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -42,7 +67,7 @@ class ArrayParserTests: XCTestCase {
42
67
}
43
68
}
44
69
45
- func testInvalidCharacterAfterFirstValue( ) throws {
70
+ func testInvalidCharacterAfterFirstValue( ) {
46
71
do {
47
72
var parser = JSONParserImpl ( bytes: [ UInt8] ( " [ true asd ] " . utf8) )
48
73
_ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -57,17 +82,28 @@ class ArrayParserTests: XCTestCase {
57
82
}
58
83
}
59
84
60
- func testHighlyNestedArray( ) throws {
61
- // test 512 should succeed
62
- let passingString = String ( repeating: " [ " , count: 512 ) + String( repeating: " ] " , count: 512 )
63
- _ = try JSONParser ( ) . parse ( bytes: [ UInt8] ( passingString. utf8) )
64
-
65
- let failingString = String ( repeating: " [ " , count: 513 )
85
+ func testNumberCommaBeforeEnd( ) {
66
86
do {
67
- _ = try JSONParser ( ) . parse ( bytes: [ UInt8] ( failingString. utf8) )
87
+ var parser = JSONParserImpl ( bytes: [ UInt8] ( " [ 1 , ] " . utf8) )
88
+ _ = try XCTUnwrap ( parser. reader. read ( ) )
89
+ _ = try parser. parseArray ( )
90
+ XCTFail ( " this point should not be reached " )
68
91
}
69
- catch JSONError . tooManyNestedArraysOrDictionaries( characterIndex: 512 ) {
70
- //expected case
92
+ catch JSONError . unexpectedCharacter( ascii: UInt8 ( ascii: " ] " ) ) {
93
+ // expected
94
+ }
95
+ catch {
96
+ XCTFail ( " Unexpected error: \( error) " )
97
+ }
98
+ }
99
+
100
+ func testIncompleteLiteralInArray( ) throws {
101
+ do {
102
+ _ = try JSONParser ( ) . parse ( bytes: [ UInt8] ( " [ nu ] " . utf8) )
103
+ XCTFail ( " this point should not be reached " )
104
+ }
105
+ catch JSONError . unexpectedCharacter( ascii: UInt8 ( ascii: " " ) ) {
106
+ // expected
71
107
}
72
108
catch {
73
109
XCTFail ( " Unexpected error: \( error) " )
0 commit comments