File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed
Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff 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+
6376public
6477extension 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
Original file line number Diff line number Diff line change 11/// Semantic marker for value that should be displayed in
22/// a field with `isSecure` property set to `true`.
33public
4- protocol IsSecretValue { }
4+ protocol IsSecretValue : SomeValidatableValue { }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments