Created EncoderTests.testEscapingDelimiters test case

This commit is contained in:
Caleb Kleveter 2019-05-20 10:44:31 -05:00
parent 0786002f9f
commit 00a5844660
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
1 changed files with 20 additions and 0 deletions

View File

@ -59,6 +59,26 @@ final class EncoderTests: XCTestCase {
}
}
}
func testEscapingDelimiters() throws {
let quotePerson = Person(firstName: "A", lastName: "J", age: 42, gender: .male, tagLine: #"All "with quotes""#)
let hashPerson = Person(firstName: "M", lastName: "A", age: 28, gender: .female, tagLine: "#iWin#")
let quoteResult = """
"first name","last_name","age","gender","tagLine"
"A","J","42","M","All ""with quotes""\"
"""
let hashResult = """
#first name#,#last_name#,#age#,#gender#,#tagLine#
#M#,#A#,#28#,#F#,###iWin###
"""
let quoteEncoder = CSVEncoder().sync
let hashEncoder = CSVEncoder(encodingOptions: .default, configuration: .init(cellSeparator: 44, cellDelimiter: 35)).sync
try XCTAssertEqual(quoteEncoder.encode([quotePerson]), Data(quoteResult.utf8))
try XCTAssertEqual(hashEncoder.encode([hashPerson]), Data(hashResult.utf8))
}
}
fileprivate struct Person: Codable, Equatable {