From 48195d6e4a2ced36a464c74100dae5c45037bb7f Mon Sep 17 00:00:00 2001 From: Christian Tietze Date: Thu, 25 Apr 2019 18:41:42 +0200 Subject: [PATCH] feature: added extra test to cover edge case (#70) Kudos to @grantkemp --- SwiftCSVTests/CSVTests.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SwiftCSVTests/CSVTests.swift b/SwiftCSVTests/CSVTests.swift index 9080b41..84987c2 100644 --- a/SwiftCSVTests/CSVTests.swift +++ b/SwiftCSVTests/CSVTests.swift @@ -42,6 +42,17 @@ class CSVTests: XCTestCase { XCTAssertEqual(expected[index], row) } } + func testInit_whenThereAreextraCarriageReturns() { + csv = CSV(string: "id,name,age\n1,Alice,18\n2,Bob,19\n3,Charlie\r\n") + let expected = [ + ["id": "1", "name": "Alice", "age": "18"], + ["id": "2", "name": "Bob", "age": "19"], + ["id": "3", "name": "Charlie", "age": ""] + ] + for (index, row) in csv.namedRows.enumerated() { + XCTAssertEqual(expected[index], row) + } + } func testInit_whenThereAreCRLFs_makesRows() { csv = CSV(string: "id,name,age\r\n1,Alice,18\r\n2,Bob,19\r\n3,Charlie,20\r\n")