Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal struct CLIArgumentParser {
if value.isEmpty {
return [""]
}
return value.components(separatedBy: ",")
return value.split(separator: ",", omittingEmptySubsequences: false).map(String.init)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ internal struct EnvironmentValueArrayDecoder {
/// - Parameter string: The source string to parse.
/// - Returns: The parsed array.
func decode(_ string: String) -> [String] {
string.split(separator: separator).map { $0.trimmed() }
string.split(separator: separator, omittingEmptySubsequences: false).map { $0.trimmed() }
}
}

Expand Down
44 changes: 42 additions & 2 deletions Tests/ConfigurationTests/EnvironmentVariablesProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ struct EnvironmentVariablesProviderTests {
"BOOL_NO": "NO",
"BOOL_THROWS_ERROR_EMPTY": "",
"BOOL_THROWS_ERROR_NOT_BOOL_STRING": "2",
"BOOLY_ARRAY_TRUE": "true,1,,YES",
"BOOLY_ARRAY_TRUE": "true,1,YES",
"BOOLY_ARRAY_FALSE": "false,0,NO",
"BOOLY_ARRAY_THROWS_1": "true,1,YESS",
"BOOLY_ARRAY_THROWS_2": "false,00,no",
"BOOLY_ARRAY_THROWS_3": "false, ,no",
"BOOLY_ARRAY_THROWS_3": " ,",
"BOOLY_ARRAY_THROWS_4": ",",
])
#expect(try sut.value(forKey: "BOOL_TRUE", type: .bool).value == true)
#expect(try sut.value(forKey: "BOOL_FALSE", type: .bool).value == false)
Expand All @@ -124,6 +125,45 @@ struct EnvironmentVariablesProviderTests {
#expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_1", type: .boolArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_2", type: .boolArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_3", type: .boolArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_4", type: .boolArray) }
}

@available(Configuration 1.0, *)
@Test func valueForKeyOfIntArrayTypes() throws {
let sut = EnvironmentVariablesProvider(
environmentVariables: [
"INTLY_ARRAY_1": "",
"INTLY_ARRAY_2": " ",
"INTLY_ARRAY_3": ",",
"INTLY_ARRAY_4": " ,",
"INTLY_ARRAY_5": "1,,2",
"INTLY_ARRAY_6": "1, ,2",
])
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_1", type: .intArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_2", type: .intArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_3", type: .intArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_4", type: .intArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_5", type: .intArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "INTLY_ARRAY_6", type: .intArray) }
}

@available(Configuration 1.0, *)
@Test func valueForKeyOfDoubleArrayTypes() throws {
let sut = EnvironmentVariablesProvider(
environmentVariables: [
"DOUBLY_ARRAY_1": "",
"DOUBLY_ARRAY_2": " ",
"DOUBLY_ARRAY_3": ",",
"DOUBLY_ARRAY_4": " ,",
"DOUBLY_ARRAY_5": "1.1,,2.1",
"DOUBLY_ARRAY_6": "1.1, ,2.1",
])
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_1", type: .doubleArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_2", type: .doubleArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_3", type: .doubleArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_4", type: .doubleArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_5", type: .doubleArray) }
#expect(throws: ConfigError.self) { try sut.value(forKey: "DOUBLY_ARRAY_6", type: .doubleArray) }
}

@available(Configuration 1.0, *)
Expand Down