Skip to content

Commit

Permalink
Fix EnvironmentValuesTest on iOS 18
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Sep 17, 2024
1 parent f2f7b5f commit 05ed2cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
.swiftLanguageMode(.v5),
.enableUpcomingFeature("BareSlashRegexLiterals"),
]

if releaseVersion >= 2021 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,44 @@ struct EnvironmentValuesTest {
return
}
#endif
func compareDictDescription(result: String, initial: String, expectNew: String) {
guard #available(iOS 16.0, macOS 13.0, *) else {
#expect(result == expectNew)
return
}
guard !expectNew.isEmpty else {
#expect(result == initial)
return
}
guard let expectNewContent = expectNew.wholeMatch(of: /\[(.*)\]/)?.output.1 else {
Issue.record("Non empty string and does not contain [] in expectNew")
return
}
let expectResult = "[\(expectNewContent), " + initial.dropFirst()
#expect(result == expectResult)
}

var env = EnvironmentValues()
#expect(env.description == "[]")

let initialDescription = env.description
if #unavailable(iOS 18, macOS 15) {
#expect(env.description == "[]")
}

var bool = env[BoolKey.self]
#expect(bool == BoolKey.defaultValue)
#expect(env.description == "[]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "")

env[BoolKey.self] = bool
#expect(env.description == "[\(BoolKey.name) = \(bool)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool)]")

env[BoolKey.self] = !bool
bool = env[BoolKey.self]
#expect(bool == !BoolKey.defaultValue)
#expect(env.description == "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")

let value = 1
env[IntKey.self] = value
#expect(env.description == "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
}
}

0 comments on commit 05ed2cd

Please sign in to comment.