-
Notifications
You must be signed in to change notification settings - Fork 1
Update tests to use Swift Testing #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates existing XCTest-based validation tests to the new Swift Testing framework, replacing assertions with #expect, adding @Suite/@Test annotations, and updating the package tools version.
- Replaced
import XCTestandXCTAssert…calls withimport Testing,@Suite,@Test, and#expectsyntax. - Added suite and test annotations across all validator test files.
- Updated
Package.swiftto swift-tools-version 6.0 for compatibility with the Testing package.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/ValidationKitTests/StringTests.swift | Migrated string prefix tests to Swift Testing syntax |
| Tests/ValidationKitTests/SelectionTests.swift | Updated selection tests with @Suite, @Test, and #expect |
| Tests/ValidationKitTests/OperatorTests.swift | Converted combination tests to the Testing framework |
| Tests/ValidationKitTests/LengthTests.swift | Refactored min/max/exact length tests with new syntax |
| Tests/ValidationKitTests/EmptyTests.swift | Migrated empty/notEmpty validator tests |
| Tests/ValidationKitTests/EmailTests.swift | Updated email tests, added annotations and #expect |
| Tests/ValidationKitTests/DateTests.swift | Switched date validation tests and imported Foundation |
| Tests/ValidationKitTests/AcceptedTests.swift | Converted accepted validator tests to Swift Testing |
| Package.swift | Bumped swift-tools-version to 6.0 for Testing support |
Comments suppressed due to low confidence (1)
Tests/ValidationKitTests/EmailTests.swift:43
- This test method is missing a
@Testannotation, so it won't be discovered by the Testing framework. Please add@Test("Invalid email addresses should fail validation").
func testInvalidEmailAddresses() throws {
|
|
||
| // Error message | ||
| XCTAssertEqual(ValidationError.invalidPrefix(prefix: "hoi").localizedDescription, "must start with hoi") | ||
| #expect(ValidationError.invalidPrefix(prefix: "hoi").localizedDescription == "must start with hoi", "Error message should contain the required prefix") |
Copilot
AI
Jul 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is using invalidPrefix(prefix: "hoi") but the validator was created with prefix "42". Update the error check to match the actual prefix under test.
| #expect(ValidationError.invalidPrefix(prefix: "hoi").localizedDescription == "must start with hoi", "Error message should contain the required prefix") | |
| #expect(ValidationError.invalidPrefix(prefix: "42").localizedDescription == "must start with 42", "Error message should contain the required prefix") |
|
|
||
| // Error message | ||
| XCTAssertEqual(ValidationError.notExactLength(exactLength: 5).localizedDescription, "must be exactly 5 characters long") | ||
| #expect(ValidationError.notExactLength(exactLength: 5).localizedDescription == "must be exactly 5 characters long", "Error message should specify exact length requirement") |
Copilot
AI
Jul 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exactLength validator was initialized with 10, but the error expectation uses exactLength: 5. It should assert against 10 to match the tested validator.
| #expect(ValidationError.notExactLength(exactLength: 5).localizedDescription == "must be exactly 5 characters long", "Error message should specify exact length requirement") | |
| #expect(ValidationError.notExactLength(exactLength: 10).localizedDescription == "must be exactly 10 characters long", "Error message should specify exact length requirement") |
| XCTAssertFalse(validator.validate(input: "").isValid) | ||
| XCTAssertFalse(validator.validate(input: "foo").isValid) | ||
| XCTAssertFalse(validator.validate(input: "foobarbazquuxwhopper").isValid) | ||
| #expect(validator.validate(input: "").isValid == true, "Empty string should not be valid") |
Copilot
AI
Jul 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion checks isValid == true but the description says the empty string should be invalid. Change == true to == false.
| #expect(validator.validate(input: "").isValid == true, "Empty string should not be valid") | |
| #expect(validator.validate(input: "").isValid == false, "Empty string should not be valid") |
| @Test("Date validation with custom formatter") | ||
| func isDate() { | ||
| let dateFormatter = DateFormatter() | ||
| dateFormatter.dateFormat = "YYYY-MM-DD HH:mm:ss" |
Copilot
AI
Jul 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using YYYY and DD in dateFormat can lead to unexpected results—use lowercase yyyy-MM-dd HH:mm:ss for calendar year and day-of-month.
| dateFormatter.dateFormat = "YYYY-MM-DD HH:mm:ss" | |
| dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" |
No description provided.