@@ -76,12 +76,24 @@ class EnumeratedViewTests: XCTestCase {
7676 XCTAssertEqual ( csv. columns, expectedColumns)
7777 }
7878
79- func testSerialization( ) {
79+ func testSerialization( ) throws {
80+ // Comma-separated values.
8081 XCTAssertEqual ( csv. serialized, " id,name,age \n 1,Alice,18 \n 2,Bob,19 \n 3,Charlie,20 " )
81- }
8282
83- func testSerializationWithDoubleQuotes ( ) throws {
83+ // Comma-separated values with double quotes and embedded delimiters in cells.
8484 csv = try CSV < Enumerated > ( string: " id, \" the, name \" ,age \n 1, \" Alice, In, Wonderland \" ,18 \n 2,Bob,19 \n 3,Charlie,20 " )
8585 XCTAssertEqual ( csv. serialized, " id, \" the, name \" ,age \n 1, \" Alice, In, Wonderland \" ,18 \n 2,Bob,19 \n 3,Charlie,20 " )
86+ 87+ // Tab-separated values with implicit delimiter (delimiter guessing).
88+ csv = try CSV < Enumerated > ( string: " id \t name \t age \n 1 \t Alice \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " )
89+ XCTAssertEqual ( csv. serialized, " id \t name \t age \n 1 \t Alice \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " )
90+ 91+ // Tab-separated values with double quotes and embedded delimiters in cells.
92+ csv = try CSV < Enumerated > ( string: " id \t \" the \t name \" \t age \n 1 \t \" Alice \t In \t Wonderland \" \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " )
93+ XCTAssertEqual ( csv. serialized, " id \t \" the \t name \" \t age \n 1 \t \" Alice \t In \t Wonderland \" \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " )
94+ 95+ // Tab-separated values with explicit alternate delimiter (tab) and embedded default delimiters (commas) in cells.
96+ csv = try CSV < Enumerated > ( string: " id \t the, name,age \n 1 \t Alice, In, Wonderland \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " , delimiter: . tab)
97+ XCTAssertEqual ( csv. serialized, " id \t the, name,age \n 1 \t Alice, In, Wonderland \t 18 \n 2 \t Bob \t 19 \n 3 \t Charlie \t 20 " )
8698 }
8799}
0 commit comments