Skip to content

Commit 209b577

Browse files
Merge tag '5.4.1' into develop
[FIX] incorrect faulty implementation of `isSecret` property of vlaidatable value
2 parents 3552f6d + 34177db commit 209b577

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

Sources/Core/3_Value/*SomeValidatableValue.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ protocol SomeValidatableValue: DisplayNamed
3838

3939
associatedtype Valid: Codable
4040

41+
static
42+
var isSecret: Bool { get }
43+
4144
/// Helps identify whatever given value considered as empty.
4245
static
4346
func isEmpty(rawValue: Raw) -> Bool
@@ -60,12 +63,29 @@ protocol SomeValidatableValue: DisplayNamed
6063

6164
// MARK: - Default implementations
6265

66+
public
67+
extension SomeValidatableValue where Self: IsSecretValue
68+
{
69+
static
70+
var isSecret: Bool
71+
{
72+
true
73+
}
74+
}
75+
6376
public
6477
extension SomeValidatableValue
6578
{
6679
static
67-
var isSecret: Bool { self is IsSecretValue }
68-
80+
var isSecret: Bool
81+
{
82+
false
83+
}
84+
}
85+
86+
public
87+
extension SomeValidatableValue
88+
{
6989
static
7090
var conditionsOnRaw: [Condition<Raw>] { [] }
7191

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/// Semantic marker for value that should be displayed in
22
/// a field with `isSecure` property set to `true`.
33
public
4-
protocol IsSecretValue {}
4+
protocol IsSecretValue: SomeValidatableValue {}

Tests/AllTests/ValidatableValueTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,22 @@ extension SpecTests
168168
XCTAssert(ColorPreference.convert(rawValue: "white") == .white)
169169
XCTAssertNil(ColorPreference.convert(rawValue: "sdfsdf"))
170170
}
171+
172+
func test_value_isSecret()
173+
{
174+
enum LastName: SomeValidatableValue
175+
{
176+
typealias Raw = String
177+
typealias Valid = String
178+
}
179+
180+
enum Pwd: SomeValidatableValue, IsSecretValue
181+
{
182+
typealias Raw = String
183+
typealias Valid = String
184+
}
185+
186+
XCTAssertFalse(NonRequired<LastName>("").metadata.isSecret)
187+
XCTAssertTrue(NonRequired<Pwd>("").metadata.isSecret)
188+
}
171189
}

0 commit comments

Comments
 (0)