@@ -45,23 +45,52 @@ struct EnvironmentValuesTest {
45
45
return
46
46
}
47
47
#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
+ if expectNewContent. isEmpty {
63
+ #expect( result == initial)
64
+ } else {
65
+ let expectResult = " [ \( expectNewContent) , " + initial. dropFirst ( )
66
+ #expect( result == expectResult)
67
+ }
68
+ #else
69
+ #expect( result == expectNew)
70
+ #endif
71
+ }
72
+
48
73
var env = EnvironmentValues ( )
49
- #expect( env. description == " [] " )
74
+
75
+ let initialDescription = env. description
76
+ if #unavailable( iOS 18 , macOS 15 ) {
77
+ #expect( env. description == " [] " )
78
+ }
50
79
51
80
var bool = env [ BoolKey . self]
52
81
#expect( bool == BoolKey . defaultValue)
53
- #expect ( env. description == " [] " )
82
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [] " )
54
83
55
84
env [ BoolKey . self] = bool
56
- #expect ( env. description == " [ \( BoolKey . name) = \( bool) ] " )
85
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [ \( BoolKey . name) = \( bool) ] " )
57
86
58
87
env [ BoolKey . self] = !bool
59
88
bool = env [ BoolKey . self]
60
89
#expect( bool == !BoolKey. defaultValue)
61
- #expect ( env. description == " [ \( BoolKey . name) = \( bool) , \( BoolKey . name) = \( BoolKey . defaultValue) ] " )
90
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [ \( BoolKey . name) = \( bool) , \( BoolKey . name) = \( BoolKey . defaultValue) ] " )
62
91
63
92
let value = 1
64
93
env [ IntKey . self] = value
65
- #expect ( env. description == " [ \( IntKey . name) = \( value) , \( BoolKey . name) = \( bool) , \( BoolKey . name) = \( BoolKey . defaultValue) ] " )
94
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [ \( IntKey . name) = \( value) , \( BoolKey . name) = \( bool) , \( BoolKey . name) = \( BoolKey . defaultValue) ] " )
66
95
}
67
96
}
0 commit comments