Skip to content

Commit 2e5b4de

Browse files
committed
Updated unit tests
1 parent e252f18 commit 2e5b4de

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ let package = Package(
1010
products: [
1111
.library(name: "TextFileKit", targets: ["TextFileKit"])
1212
],
13+
dependencies: [
14+
.package(url: "https://github.com/orchetect/swift-testing-extensions", .upToNextMajor(from: "0.2.0")),
15+
],
1316
targets: [
1417
.target(name: "TextFileKit"),
15-
.testTarget(name: "TextFileKitTests", dependencies: ["TextFileKit"])
18+
.testTarget(
19+
name: "TextFileKitTests",
20+
dependencies: [
21+
"TextFileKit",
22+
.product(name: "TestingExtensions", package: "swift-testing-extensions")
23+
],
24+
resources: [.copy("TestResource/Text Files")]
25+
)
1626
]
1727
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// TestResource.swift
3+
// TextFileKit • https://github.com/orchetect/TextFileKit
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
5+
//
6+
7+
import Foundation
8+
import Testing
9+
import TestingExtensions
10+
11+
// NOTE: DO NOT name any folders "Resources". Xcode will fail to build iOS targets.
12+
13+
/// Resources files on disk used for unit testing.
14+
extension TestResource {
15+
enum TextFiles {
16+
static let utf8_BOM_Test_csv = TestResource.File(
17+
name: "utf8-bom-test", ext: "csv", subFolder: "Text Files"
18+
)
19+
}
20+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Field1","Field2"
2+
"Row1A","Row1B"
3+
"Row2A","Row2B"

Tests/TextFileKitTests/TextFile CSV Tests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@testable import TextFileKit
88
import Testing
9+
import TestingExtensions
910

1011
@Suite struct CSV_Tests {
1112
@Test func init_Default() {
@@ -137,3 +138,37 @@ extension CSV_Tests {
137138
#expect(sv.rawText == csvRawText_CommaContainingFields)
138139
}
139140
}
141+
142+
// MARK: - BOM (Byte Order Mark) Tests
143+
144+
extension CSV_Tests {
145+
static let utf8_BOM_Test_Table: StringTable = [
146+
["Field1", "Field2"],
147+
["Row1A", "Row1B"],
148+
["Row2A", "Row2B"]
149+
]
150+
151+
@Test func utf8BOM_initURL() throws {
152+
let url = try #require(try TestResource.TextFiles.utf8_BOM_Test_csv.url())
153+
154+
let sv = try TextFile.CSV(file: url)
155+
156+
let table = sv.table
157+
try #require(table.count == 3)
158+
#expect(table[0] == Self.utf8_BOM_Test_Table[0])
159+
#expect(table[1] == Self.utf8_BOM_Test_Table[1])
160+
#expect(table[2] == Self.utf8_BOM_Test_Table[2])
161+
}
162+
163+
@Test func utf8BOM_initRawData() throws {
164+
let data = try #require(try TestResource.TextFiles.utf8_BOM_Test_csv.data())
165+
166+
let sv = try TextFile.CSV(rawData: data)
167+
168+
let table = sv.table
169+
try #require(table.count == 3)
170+
#expect(table[0] == Self.utf8_BOM_Test_Table[0])
171+
#expect(table[1] == Self.utf8_BOM_Test_Table[1])
172+
#expect(table[2] == Self.utf8_BOM_Test_Table[2])
173+
}
174+
}

0 commit comments

Comments
 (0)