@@ -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