Skip to content

Commit 69a5669

Browse files
committed
Fix EnvironmentValuesTest on iOS 18
1 parent f2f7b5f commit 69a5669

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
7272
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
7373
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
7474
.swiftLanguageMode(.v5),
75+
.enableUpcomingFeature("BareSlashRegexLiterals"),
7576
]
7677

7778
if releaseVersion >= 2021 {

[email protected]

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
6868
.enableExperimentalFeature("AccessLevelOnImport"),
6969
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
7070
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
71+
.enableUpcomingFeature("BareSlashRegexLiterals"),
7172
]
7273

7374
if releaseVersion >= 2021 {

Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift

+30-5
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,48 @@ struct EnvironmentValuesTest {
4545
return
4646
}
4747
#endif
48+
func compareDictDescription(result: String, initial: String, expectNew: String) {
49+
#if canImport(Darwin)
50+
guard #available(iOS 16.0, macOS 13.0, *) else {
51+
#expect(result == expectNew)
52+
return
53+
}
54+
guard initial != "[]" else {
55+
#expect(result == expectNew)
56+
return
57+
}
58+
guard let expectNewContent = expectNew.wholeMatch(of: /\[(.*)\]/)?.output.1 else {
59+
Issue.record("Non empty string and does not contain [] in expectNew")
60+
return
61+
}
62+
let expectResult = "[\(expectNewContent), " + initial.dropFirst()
63+
#expect(result == expectResult)
64+
#else
65+
#expect(result == expectNew)
66+
#endif
67+
}
68+
4869
var env = EnvironmentValues()
49-
#expect(env.description == "[]")
70+
71+
let initialDescription = env.description
72+
if #unavailable(iOS 18, macOS 15) {
73+
#expect(env.description == "[]")
74+
}
5075

5176
var bool = env[BoolKey.self]
5277
#expect(bool == BoolKey.defaultValue)
53-
#expect(env.description == "[]")
78+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[]")
5479

5580
env[BoolKey.self] = bool
56-
#expect(env.description == "[\(BoolKey.name) = \(bool)]")
81+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool)]")
5782

5883
env[BoolKey.self] = !bool
5984
bool = env[BoolKey.self]
6085
#expect(bool == !BoolKey.defaultValue)
61-
#expect(env.description == "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
86+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
6287

6388
let value = 1
6489
env[IntKey.self] = value
65-
#expect(env.description == "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
90+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
6691
}
6792
}

0 commit comments

Comments
 (0)