@@ -45,23 +45,48 @@ 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
+ let expectResult = " [ \( expectNewContent) , " + initial. dropFirst ( )
63
+ #expect( result == expectResult)
64
+ #else
65
+ #expect( result == expectNew)
66
+ #endif
67
+ }
68
+
48
69
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
+ }
50
75
51
76
var bool = env [ BoolKey . self]
52
77
#expect( bool == BoolKey . defaultValue)
53
- #expect ( env. description == " [] " )
78
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [] " )
54
79
55
80
env [ BoolKey . self] = bool
56
- #expect ( env. description == " [ \( BoolKey . name) = \( bool) ] " )
81
+ compareDictDescription ( result : env. description, initial : initialDescription , expectNew : " [ \( BoolKey . name) = \( bool) ] " )
57
82
58
83
env [ BoolKey . self] = !bool
59
84
bool = env [ BoolKey . self]
60
85
#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) ] " )
62
87
63
88
let value = 1
64
89
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) ] " )
66
91
}
67
92
}
0 commit comments