From c324affad1f69fcbf542a5a95ae36d6a33de5885 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 13 Oct 2025 00:17:22 +0200 Subject: [PATCH] Renamed the AgentNameValidationRule type in the library target as CamelCaseValidationRule. --- .../Errors/InputValidationError.swift | 4 ++-- ...le.swift => CamelCaseValidationRule.swift} | 18 +++++++++-------- .../SecureValidationRule.swift | 2 +- .../Use Cases/ValidateInputUseCaseTests.swift | 20 +++++++++---------- 4 files changed, 23 insertions(+), 21 deletions(-) rename Sources/DiscogsService/Internal/Validation Rules/{AgentNameValidationRule.swift => CamelCaseValidationRule.swift} (76%) diff --git a/Sources/DiscogsService/Internal/Errors/InputValidationError.swift b/Sources/DiscogsService/Internal/Errors/InputValidationError.swift index 60af7892d..8b1dca424 100644 --- a/Sources/DiscogsService/Internal/Errors/InputValidationError.swift +++ b/Sources/DiscogsService/Internal/Errors/InputValidationError.swift @@ -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. diff --git a/Sources/DiscogsService/Internal/Validation Rules/AgentNameValidationRule.swift b/Sources/DiscogsService/Internal/Validation Rules/CamelCaseValidationRule.swift similarity index 76% rename from Sources/DiscogsService/Internal/Validation Rules/AgentNameValidationRule.swift rename to Sources/DiscogsService/Internal/Validation Rules/CamelCaseValidationRule.swift index c64797d4c..630df3057 100644 --- a/Sources/DiscogsService/Internal/Validation Rules/AgentNameValidationRule.swift +++ b/Sources/DiscogsService/Internal/Validation Rules/CamelCaseValidationRule.swift @@ -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])+)+" + } diff --git a/Sources/DiscogsService/Internal/Validation Rules/SecureValidationRule.swift b/Sources/DiscogsService/Internal/Validation Rules/SecureValidationRule.swift index 1873ed55a..0dd3e2d21 100644 --- a/Sources/DiscogsService/Internal/Validation Rules/SecureValidationRule.swift +++ b/Sources/DiscogsService/Internal/Validation Rules/SecureValidationRule.swift @@ -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}$" } diff --git a/Tests/DiscogsService/Cases/Internal/Use Cases/ValidateInputUseCaseTests.swift b/Tests/DiscogsService/Cases/Internal/Use Cases/ValidateInputUseCaseTests.swift index b93e37c42..19fc17fa6 100644 --- a/Tests/DiscogsService/Cases/Internal/Use Cases/ValidateInputUseCaseTests.swift +++ b/Tests/DiscogsService/Cases/Internal/Use Cases/ValidateInputUseCaseTests.swift @@ -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.