Skip to content

Commit c80a145

Browse files
committed
Test folder hierarchy rename
1 parent 82f5aa2 commit c80a145

12 files changed

+96
-117
lines changed

tests/CodableTests/CodableNumericBoolTests.swift

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
import XCTest
22
import CodableCSV
33

4-
/// Tests checking support for encoding/decoding floating-points.
4+
/// Check support for encoding/decoding floating-points.
55
final class CodableFloatingPointTests: XCTestCase {
66
override func setUp() {
77
self.continueAfterFailure = false
88
}
99
}
1010

1111
extension CodableFloatingPointTests {
12+
/// Representation of a CSV row.
1213
private struct _Student: Codable, Equatable {
14+
/// A student's name.
1315
var name: String
16+
/// A student's age.
1417
var age: Double
1518
}
1619
}
1720

1821
extension CodableFloatingPointTests {
19-
/// Test the regular floating-point encoding/decoding.
22+
/// Tests the regular floating-point encoding/decoding.
2023
func testRegularUsage() throws {
21-
let encoder = CSVEncoder { $0.headers = ["name", "age"] }
22-
let students: [_Student] = [
23-
.init(name: "Heidrun", age: 27.3),
24-
.init(name: "Gudrun", age: 62.0008),
25-
]
24+
let rows = [_Student(name: "Heidrun", age: 27.3),
25+
_Student(name: "Gudrun", age: 62.0008)]
2626

27-
let data = try encoder.encode(students, into: Data.self)
27+
let encoder = CSVEncoder { $0.headers = ["name", "age"] }
28+
let data = try encoder.encode(rows, into: Data.self)
2829

2930
let decoder = CSVDecoder { $0.headerStrategy = .firstLine }
3031
let result = try decoder.decode([_Student].self, from: data)
31-
XCTAssertEqual(students, result)
32+
XCTAssertEqual(rows, result)
3233
}
3334

34-
/// Test the regular floating-point encoding/decoding.
35+
/// Tests the error throwing/handling.
3536
func testThrows() throws {
37+
let rows = [_Student(name: "Heidrun", age: 27.3),
38+
_Student(name: "Gudrun", age: 62.0008),
39+
_Student(name: "Brunhilde", age: .infinity)]
40+
3641
let encoder = CSVEncoder { $0.headers = ["name", "age"] }
37-
let students: [_Student] = [
38-
.init(name: "Heidrun", age: 27.3),
39-
.init(name: "Gudrun", age: 62.0008),
40-
.init(name: "Brunhilde", age: .infinity)
41-
]
42-
XCTAssertThrowsError(try encoder.encode(students, into: Data.self))
42+
XCTAssertThrowsError(try encoder.encode(rows, into: Data.self))
4343

4444
let decoder = CSVDecoder { $0.headerStrategy = .firstLine }
4545
let data = """
@@ -51,26 +51,23 @@ extension CodableFloatingPointTests {
5151
XCTAssertThrowsError(try decoder.decode([_Student].self, from: data))
5252
}
5353

54-
/// Test the regular floating-point encoding/decoding.
55-
func testConversion() throws {
56-
let students: [_Student] = [
57-
.init(name: "Heidrun", age: 27.3),
58-
.init(name: "Gudrun", age: 62.0008),
59-
.init(name: "Brunhilde", age: .infinity)
60-
]
54+
/// Tests the the non conforming floating-point conversions.
55+
func testNonConformity() throws {
56+
let rows = [_Student(name: "Heidrun", age: 27.3),
57+
_Student(name: "Gudrun", age: 62.0008),
58+
_Student(name: "Brunhilde", age: .infinity)]
6159

6260
let encoder = CSVEncoder {
6361
$0.headers = ["name", "age"]
6462
$0.nonConformingFloatStrategy = .convert(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
6563
}
66-
67-
let data = try encoder.encode(students, into: Data.self)
64+
let data = try encoder.encode(rows, into: Data.self)
6865

6966
let decoder = CSVDecoder {
7067
$0.headerStrategy = .firstLine
7168
$0.nonConformingFloatStrategy = .convert(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
7269
}
7370
let result = try decoder.decode([_Student].self, from: data)
74-
XCTAssertEqual(students, result)
71+
XCTAssertEqual(rows, result)
7572
}
7673
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import XCTest
2+
import CodableCSV
3+
4+
/// Check support for encoding/decoding numeric Booleans.
5+
final class CodableNumericBoolTests: XCTestCase {
6+
override func setUp() {
7+
self.continueAfterFailure = false
8+
}
9+
}
10+
11+
extension CodableNumericBoolTests {
12+
/// Representation of a CSV row exclusively composed of Booleans.
13+
private struct _Row: Codable, Equatable {
14+
var a: Bool
15+
var b: Bool
16+
var c: Bool?
17+
}
18+
}
19+
20+
extension CodableNumericBoolTests {
21+
/// Tests the regular numeric Boolean encoding/decoding.
22+
func testRegularUsage() throws {
23+
let rows = [_Row(a: true, b: false, c: nil),
24+
_Row(a: true, b: true, c: false),
25+
_Row(a: false, b: false, c: true)]
26+
let string = """
27+
a,b,c
28+
1,0,
29+
1,1,0
30+
0,0,1
31+
""".appending("\n")
32+
33+
34+
let encoder = CSVEncoder {
35+
$0.headers = ["a", "b", "c"]
36+
$0.boolStrategy = .numeric
37+
}
38+
XCTAssertEqual(string, try encoder.encode(rows, into: String.self))
39+
40+
let decoder = CSVDecoder {
41+
$0.headerStrategy = .firstLine
42+
$0.boolStrategy = .numeric
43+
}
44+
XCTAssertEqual(rows, try decoder.decode([_Row].self, from: string.data(using: .utf8)!))
45+
46+
let shuffledString = """
47+
c,a,b
48+
,1,0
49+
0,1,1
50+
1,0,0
51+
""".appending("\n")
52+
XCTAssertEqual(rows, try decoder.decode([_Row].self, from: shuffledString.data(using: .utf8)!))
53+
}
54+
55+
/// Tests the error throwing/handling.
56+
func testThrows() throws {
57+
// b = nil on 2nd row, must throw an exception.
58+
let data = """
59+
a,b,c
60+
1,0,
61+
1,,0
62+
""".data(using: .utf8)!
63+
64+
let decoder = CSVDecoder {
65+
$0.headerStrategy = .firstLine
66+
$0.boolStrategy = .numeric
67+
}
68+
XCTAssertThrowsError(try decoder.decode([_Row].self, from: data))
69+
}
70+
71+
}
72+

tests/CodableTests/DecodingRegularUsageTests.swift renamed to tests/declarative/DecodingRegularUsageTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import XCTest
22
import CodableCSV
33

4-
/// Tests checking the regular decoding usage.
4+
/// Checks the regular decoding usage.
55
final class DecodingRegularUsageTests: XCTestCase {
66
override func setUp() {
77
self.continueAfterFailure = false
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)