@@ -19,6 +19,31 @@ class ArrayParserTests: XCTestCase {
1919 XCTAssertEqual ( result, [ . bool( true ) ] )
2020 }
2121
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+
2247 func testSimpleTrueAndStringArray( ) throws {
2348 var parser = JSONParserImpl ( bytes: [ UInt8] ( #"[ true , "hello" ]"# . utf8) )
2449 let _ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -27,7 +52,7 @@ class ArrayParserTests: XCTestCase {
2752 XCTAssertEqual ( result, [ . bool( true ) , . string( " hello " ) ] )
2853 }
2954
30- func testCommaBeforeEnd( ) throws {
55+ func testCommaBeforeEnd( ) {
3156 do {
3257 var parser = JSONParserImpl ( bytes: [ UInt8] ( " [ true , ] " . utf8) )
3358 _ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -42,7 +67,7 @@ class ArrayParserTests: XCTestCase {
4267 }
4368 }
4469
45- func testInvalidCharacterAfterFirstValue( ) throws {
70+ func testInvalidCharacterAfterFirstValue( ) {
4671 do {
4772 var parser = JSONParserImpl ( bytes: [ UInt8] ( " [ true asd ] " . utf8) )
4873 _ = try XCTUnwrap ( parser. reader. read ( ) )
@@ -57,17 +82,28 @@ class ArrayParserTests: XCTestCase {
5782 }
5883 }
5984
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( ) {
6686 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 " )
6891 }
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
71107 }
72108 catch {
73109 XCTFail ( " Unexpected error: \( error) " )
0 commit comments