Renamed the AgentNameValidationRule type in the library target as CamelCaseValidationRule.
This commit is contained in:
@@ -18,8 +18,8 @@ enum InputValidationError: Error {
|
||||
case inputIsEmpty
|
||||
/// An input is nil.
|
||||
case inputIsNil
|
||||
/// An input does not comply with the user agent name requirements.
|
||||
case inputNotAgentName
|
||||
/// An input is not camel-case.
|
||||
case inputNotCamelCase
|
||||
/// An input does not comply with the consumer key requirements.
|
||||
case inputNotConsumerKey
|
||||
/// An input does not comply with the consumer secret requirements.
|
||||
|
||||
+10
-8
@@ -12,7 +12,8 @@
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
struct AgentNameValidationRule: InputValidationRule {
|
||||
/// A validation rule type that checks whether an input is camel-case or not.
|
||||
struct CamelCaseValidationRule: InputValidationRule {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
@@ -30,18 +31,18 @@ struct AgentNameValidationRule: InputValidationRule {
|
||||
|
||||
// MARK: - Definitions
|
||||
|
||||
extension InputValidationRule where Self == AgentNameValidationRule {
|
||||
extension InputValidationRule where Self == CamelCaseValidationRule {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// A validation rule that checks whether an input is camel-cased or not.
|
||||
static var agentName: Self { .init() }
|
||||
static var camelCase: Self { .init() }
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension AgentNameValidationRule {
|
||||
private extension CamelCaseValidationRule {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
@@ -58,9 +59,9 @@ private extension AgentNameValidationRule {
|
||||
}
|
||||
|
||||
guard input.fullyMatch(
|
||||
pattern: .init(format: .Pattern.agentName)
|
||||
pattern: .init(format: .Pattern.camelCase)
|
||||
) else {
|
||||
throw InputValidationError.inputNotAgentName
|
||||
throw InputValidationError.inputNotCamelCase
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -71,6 +72,7 @@ private extension AgentNameValidationRule {
|
||||
// MARK: - Constants
|
||||
|
||||
private extension String.Pattern {
|
||||
/// A regular expression pattern to match the user agent name input against.
|
||||
static let agentName = "^([A-Z]([a-z]|[0-9])+)+$"
|
||||
/// A regular expression pattern that represents camel-cased inputs.
|
||||
static let camelCase = "([A-Z]([a-z]|[0-9])+)+"
|
||||
|
||||
}
|
||||
@@ -107,6 +107,6 @@ private extension SecureValidationRule {
|
||||
// MARK: - Constants
|
||||
|
||||
private extension String.Pattern {
|
||||
/// A regular expression pattern to match the security inputs against.
|
||||
/// A regular expression pattern that represents security inputs.
|
||||
static let securityInput = "^([a-z]|[A-Z]){%d}$"
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ struct ValidateInputUseCaseTests {
|
||||
@Test(arguments: zip(
|
||||
Input.inputsAgentName,
|
||||
Output.inputsAgentName
|
||||
)) func `validate agent name`(
|
||||
)) func `validate camel case`(
|
||||
input: String,
|
||||
expects error: InputValidationError?
|
||||
) async throws {
|
||||
@@ -106,15 +106,15 @@ struct ValidateInputUseCaseTests {
|
||||
)
|
||||
}
|
||||
#else
|
||||
@Test("validate agent name", arguments: zip(
|
||||
Input.inputsAgentName,
|
||||
Output.inputsAgentName
|
||||
)) func validateAgentName(
|
||||
@Test("validate camel case", arguments: zip(
|
||||
Input.inputsCamelCase,
|
||||
Output.inputsCamelCase
|
||||
)) func validateCamelCase(
|
||||
input: String,
|
||||
expects error: InputValidationError?
|
||||
) async throws {
|
||||
try assertValidate(
|
||||
rule: .agentName,
|
||||
rule: .camelCase,
|
||||
input: input,
|
||||
expects: error
|
||||
)
|
||||
@@ -231,8 +231,8 @@ private extension ValidateInputUseCaseTests {
|
||||
// MARK: - Constants
|
||||
|
||||
private extension Input {
|
||||
/// A list of inputs to validate against a user agent name validation rule.
|
||||
static let inputsAgentName: [String] = ["SampleApp", "Sample4pp", "SampleApp1", "SampleApp🚀", "Sample App", "Sample-App", "Sample_App"]
|
||||
/// A list of inputs to validate against a camel-case validation rule.
|
||||
static let inputsCamelCase: [String] = ["SampleApp", "Sample4pp", "SampleApp1", "SampleApp🚀", "Sample App", "Sample-App", "Sample_App"]
|
||||
/// A list of inputs to validate against the not empty validation rule.
|
||||
static let inputsNotEmpty: [String] = ["Something", .empty]
|
||||
/// A list of inputs to validate against the not nil validation rule.
|
||||
@@ -246,8 +246,8 @@ private extension Input {
|
||||
}
|
||||
|
||||
private extension Output {
|
||||
/// A list of expected input validation errors to be thrown after validating inputs against the user agent name validation rule.
|
||||
static let inputsAgentName: [InputValidationError?] = [nil, nil, nil, .inputNotAgentName, .inputNotAgentName, .inputNotAgentName, .inputNotAgentName]
|
||||
/// A list of expected input validation errors to be thrown after validating inputs against the camel-case validation rule.
|
||||
static let inputsCamelCase: [InputValidationError?] = [nil, nil, nil, .inputNotCamelCase, .inputNotCamelCase, .inputNotCamelCase, .inputNotCamelCase]
|
||||
/// A list of expected input validation errors to be thrown after validating inputs against the not empty validation rule.
|
||||
static let inputsNotEmpty: [InputValidationError?] = [nil, .inputIsEmpty]
|
||||
/// A list of expected input validation errors to be thrown after validating inputs against the not nil validation rule.
|
||||
|
||||
Reference in New Issue
Block a user