From 630f8a03f715bd5b6f7c7e8c179900ae95af78b3 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 12 Oct 2025 13:57:54 +0200 Subject: [PATCH] Implemented the NotEmptyValidationRule type in the library target. --- .../NotEmptyValidationRule.swift | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift diff --git a/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift b/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift new file mode 100644 index 000000000..dbcbfbfea --- /dev/null +++ b/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift @@ -0,0 +1,38 @@ +// ===----------------------------------------------------------------------=== +// +// This source file is part of the DiscogsService open source project +// +// Copyright (c) 2025 Röck+Cöde VoF. and the DiscogsService project authors +// Licensed under Apache license v2.0 +// +// See LICENSE for license information +// See CONTRIBUTORS for the list of DiscogsService project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +// ===----------------------------------------------------------------------=== + +/// A validation rule type that checks whether an input is empty or not. +struct NotEmptyValidationRule: InputValidationRule { + + // MARK: Functions + + func validate(_ input: String?) throws -> Bool { + guard let input else { + return false + } + guard !input.isEmpty else { + throw InputValidationError.inputIsEmpty + } + + return true + } + +} + +// MARK: - Constants + +extension InputValidationRule where Self == NotEmptyValidationRule { + /// A validation rule that checks whether an input is empty or not. + static var notEmpty: Self { .init() } +}