-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb4e444
commit 88feb98
Showing
5 changed files
with
168 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,18 @@ import Testing | |
@testable import NativeRegexExamples | ||
import CustomDump | ||
|
||
@Suite("Email") | ||
struct EmailTests: RegexTestSuite { | ||
@Suite(.tags(.literals, .email)) | ||
struct EmailTests_Literal: RegexTestSuite { | ||
@Test(arguments: ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"]) | ||
func wholeMatch(_ input: String) throws { | ||
let wholeMatchOptional = input.wholeMatch(of: RegexLiterals.email) | ||
let wholeMatch = try #require(wholeMatchOptional) // unwrap | ||
let output = String(wholeMatch.output) // convert Substring to String | ||
expectNoDifference(output, input) | ||
} | ||
|
||
@Test("NOT wholeMatch(of:)", | ||
arguments: ["@email.com", "myName@"] | ||
arguments: ["@email.com", "myName@"] | ||
) | ||
func not_wholeMatch(_ input: String) throws { | ||
let not_wholeMatch = input.wholeMatch(of: RegexLiterals.email) | ||
|
@@ -38,4 +38,40 @@ some other text ⬛︎⬛︎⬛︎ | |
} | ||
} | ||
|
||
@Suite(.tags(.builderDSL, .email)) | ||
struct EmailTests_DSL: RegexTestSuite { | ||
@Test(arguments: ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"]) | ||
func wholeMatch(_ input: String) throws { | ||
let wholeMatchOptional = input.wholeMatch(of: RegexBuilders.email) | ||
let wholeMatch = try #require(wholeMatchOptional) // unwrap | ||
let output = String(wholeMatch.output) // convert Substring to String | ||
expectNoDifference(output, input) | ||
} | ||
|
||
@Test("NOT wholeMatch(of:)", | ||
arguments: ["@email.com", "myName@"] | ||
) | ||
func not_wholeMatch(_ input: String) throws { | ||
let not_wholeMatch = input.wholeMatch(of: RegexBuilders.email) | ||
#expect( | ||
not_wholeMatch == nil, | ||
"False positive match found: \(input) should not match \(not_wholeMatch)" | ||
) | ||
} | ||
|
||
@Test("replace(_ regex: with:)") | ||
func replace() { | ||
var text = """ | ||
[email protected] some other text | ||
some other text [email protected] | ||
""" | ||
text.replace(RegexBuilders.email, with: "⬛︎⬛︎⬛︎") | ||
let expected = """ | ||
⬛︎⬛︎⬛︎ some other text | ||
some other text ⬛︎⬛︎⬛︎ | ||
""" | ||
expectNoDifference(expected, text) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters