Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Jan 3, 2025
1 parent e252f18 commit 2e5b4de
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ let package = Package(
products: [
.library(name: "TextFileKit", targets: ["TextFileKit"])
],
dependencies: [
.package(url: "https://github.com/orchetect/swift-testing-extensions", .upToNextMajor(from: "0.2.0")),
],
targets: [
.target(name: "TextFileKit"),
.testTarget(name: "TextFileKitTests", dependencies: ["TextFileKit"])
.testTarget(
name: "TextFileKitTests",
dependencies: [
"TextFileKit",
.product(name: "TestingExtensions", package: "swift-testing-extensions")
],
resources: [.copy("TestResource/Text Files")]
)
]
)
20 changes: 20 additions & 0 deletions Tests/TextFileKitTests/TestResource/TestResource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// TestResource.swift
// TextFileKit • https://github.com/orchetect/TextFileKit
// © 2021-2024 Steffan Andrews • Licensed under MIT License
//

import Foundation
import Testing
import TestingExtensions

// NOTE: DO NOT name any folders "Resources". Xcode will fail to build iOS targets.

/// Resources files on disk used for unit testing.
extension TestResource {
enum TextFiles {
static let utf8_BOM_Test_csv = TestResource.File(
name: "utf8-bom-test", ext: "csv", subFolder: "Text Files"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Field1","Field2"
"Row1A","Row1B"
"Row2A","Row2B"
35 changes: 35 additions & 0 deletions Tests/TextFileKitTests/TextFile CSV Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@testable import TextFileKit
import Testing
import TestingExtensions

@Suite struct CSV_Tests {
@Test func init_Default() {
Expand Down Expand Up @@ -137,3 +138,37 @@ extension CSV_Tests {
#expect(sv.rawText == csvRawText_CommaContainingFields)
}
}

// MARK: - BOM (Byte Order Mark) Tests

extension CSV_Tests {
static let utf8_BOM_Test_Table: StringTable = [
["Field1", "Field2"],
["Row1A", "Row1B"],
["Row2A", "Row2B"]
]

@Test func utf8BOM_initURL() throws {
let url = try #require(try TestResource.TextFiles.utf8_BOM_Test_csv.url())

let sv = try TextFile.CSV(file: url)

let table = sv.table
try #require(table.count == 3)
#expect(table[0] == Self.utf8_BOM_Test_Table[0])
#expect(table[1] == Self.utf8_BOM_Test_Table[1])
#expect(table[2] == Self.utf8_BOM_Test_Table[2])
}

@Test func utf8BOM_initRawData() throws {
let data = try #require(try TestResource.TextFiles.utf8_BOM_Test_csv.data())

let sv = try TextFile.CSV(rawData: data)

let table = sv.table
try #require(table.count == 3)
#expect(table[0] == Self.utf8_BOM_Test_Table[0])
#expect(table[1] == Self.utf8_BOM_Test_Table[1])
#expect(table[2] == Self.utf8_BOM_Test_Table[2])
}
}

0 comments on commit 2e5b4de

Please sign in to comment.