-
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.
commit 55115e0 Author: Alex O <[email protected]> Date: Mon Nov 8 15:21:46 2021 +0300 Add remained tests commit fa36b8e Author: Alex O <[email protected]> Date: Mon Nov 8 15:21:28 2021 +0300 Clean up extended regexps enums commit f77d652 Author: Alex O <[email protected]> Date: Mon Nov 8 15:20:54 2021 +0300 Fix validated failure case comparison commit 966731d Author: Alex O <[email protected]> Date: Mon Nov 8 15:20:17 2021 +0300 Fix MultiRegex right error return commit a670f07 Author: Alex O <[email protected]> Date: Mon Nov 8 15:19:40 2021 +0300 Add more regexps
- Loading branch information
Showing
7 changed files
with
126 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import XCTest | ||
import Combine | ||
@testable import CombineValidate | ||
|
||
class MultiRegexValidatorTests: XCTestCase { | ||
class ViewModel: ObservableObject { | ||
|
||
@Published var email = "" | ||
@Published var validationResult: Validated<Void> = .untouched | ||
|
||
public lazy var emailValidator: ValidationPublisher = { | ||
$email.validateWithMultiRegex( | ||
regexs: [RegularPattern.mustIncludeNumbers, RegularPattern.mustIncludeSpecialSymbols, RegularPattern.mustIncludeCapitalLetters], | ||
errors: ["Should be one number at least", "Should be one special symbol at least", "Should be one capital letter at least"], | ||
tableName: nil | ||
) | ||
}() | ||
|
||
private var subscription = Set<AnyCancellable>() | ||
|
||
init() { | ||
emailValidator | ||
.assign(to: \.validationResult, on: self) | ||
.store(in: &subscription) | ||
} | ||
} | ||
|
||
let viewModel = ViewModel() | ||
|
||
func testIgnoreFirstValue() { | ||
XCTAssertEqual(viewModel.validationResult, .untouched) | ||
} | ||
|
||
func testFullyInvalidValue() { | ||
viewModel.email = "" | ||
|
||
XCTAssertEqual( | ||
viewModel.validationResult, | ||
.failure(reason: "Should be one number at least", tableName: nil) | ||
) | ||
} | ||
|
||
func testValueWithOneNumber() { | ||
viewModel.email = "1" | ||
|
||
XCTAssertEqual(viewModel.validationResult, .failure(reason: "Should be one special symbol at least", tableName: nil)) | ||
} | ||
|
||
func testValueWithOneNumberAndSpecialSymbol() { | ||
viewModel.email = "1%" | ||
|
||
XCTAssertEqual( | ||
viewModel.validationResult, | ||
.failure(reason: "Should be one capital letter at least", tableName: nil) | ||
) | ||
} | ||
|
||
func testValueWithOneNumberAndSpecialSymbolAndCapitalLetter() { | ||
viewModel.email = "1%A" | ||
|
||
XCTAssertEqual(viewModel.validationResult, .success(.none)) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import XCTest | ||
import Combine | ||
@testable import CombineValidate | ||
|
||
class RegexValidatorTests: XCTestCase { | ||
class ViewModel: ObservableObject { | ||
|
||
@Published var email = "" | ||
@Published var validationResult: Validated<Void> = .untouched | ||
|
||
public lazy var emailValidator: ValidationPublisher = { | ||
$email.validateWithRegex(regex: RegularPattern.email, error: "Should be email", tableName: nil) | ||
}() | ||
|
||
private var subscription = Set<AnyCancellable>() | ||
|
||
init() { | ||
emailValidator | ||
.assign(to: \.validationResult, on: self) | ||
.store(in: &subscription) | ||
} | ||
} | ||
|
||
let viewModel = ViewModel() | ||
|
||
func testIgnoreFirstValue() { | ||
XCTAssertEqual(viewModel.validationResult, .untouched) | ||
} | ||
|
||
func testValidEmailValue() { | ||
viewModel.email = "[email protected]" | ||
|
||
XCTAssertEqual(viewModel.validationResult, .success(.none)) | ||
} | ||
|
||
func testInvalidEmailValue() { | ||
viewModel.email = "someemailgmail.com" | ||
|
||
XCTAssertEqual(viewModel.validationResult, .failure(reason: "Should be email", tableName: nil)) | ||
} | ||
} |