Skip to content

Commit

Permalink
Fix patterns for associated values
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardiman committed Jul 3, 2019
1 parent da04441 commit 880ef2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Config/ConfigurationProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct ConfigurationProperty<T>: Property, AssociatedPropertyKeyProviding {
}

func keyValue(for scheme: String) -> String {
let overrideValue = overrides.first(where: { scheme.range(of: $0.key, options: .regularExpression) != nil })?.value ?? defaultValue
let overrideValue = overrides.first(where: { scheme.range(of: pattern(for: $0.key), options: .regularExpression) != nil })?.value ?? defaultValue
guard let value = overrideValue as? String else {
fatalError("Cannot retrieve keyValue for type \(T.self). Type must be String.")
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/ConfigTests/ConfigurationFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class ConfigurationFileTests: XCTestCase {
// swiftlint:disable force_unwrapping type_body_length file_length superfluous_disable_command
public enum Test {
public static let associatedProperty: String = #"correct"#
public static let propertyNotUsingPattern: String = #"test value"#
public static let propertyUsingPattern: String = #"test value"#
Expand Down Expand Up @@ -515,5 +517,13 @@ private let configurationWithCommonPatterns: [String: Any] = [
"overrides": [
"(PROD|STAGING)": "test value"
]
],
"associatedProperty": [
"type": "String",
"associatedProperty": "propertyUsingPattern",
"defaultValue": "wrong",
"overrides": [
"test value": "correct"
]
]
]

0 comments on commit 880ef2b

Please sign in to comment.