@@ -93,6 +93,89 @@ mod debug_struct {
93
93
format!( "{:#?}" , Bar )
94
94
) ;
95
95
}
96
+
97
+ #[ test]
98
+ fn test_only_non_exhaustive ( ) {
99
+ struct Foo ;
100
+
101
+ impl fmt:: Debug for Foo {
102
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
103
+ fmt. debug_struct ( "Foo" )
104
+ . finish_non_exhaustive ( )
105
+ }
106
+ }
107
+
108
+
109
+ assert_eq ! ( "Foo { .. }" , format!( "{:?}" , Foo ) ) ;
110
+ assert_eq ! (
111
+ "Foo {
112
+ ..
113
+ }" ,
114
+ format!( "{:#?}" , Foo ) ) ;
115
+ }
116
+
117
+ #[ test]
118
+ fn test_multiple_and_non_exhaustive ( ) {
119
+ struct Foo ;
120
+
121
+ impl fmt:: Debug for Foo {
122
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
123
+ fmt. debug_struct ( "Foo" )
124
+ . field ( "bar" , & true )
125
+ . field ( "baz" , & format_args ! ( "{}/{}" , 10 , 20 ) )
126
+ . finish_non_exhaustive ( )
127
+ }
128
+ }
129
+
130
+ assert_eq ! ( "Foo { bar: true, baz: 10/20, .. }" , format!( "{:?}" , Foo ) ) ;
131
+ assert_eq ! (
132
+ "Foo {
133
+ bar: true,
134
+ baz: 10/20,
135
+ ..
136
+ }" ,
137
+ format!( "{:#?}" , Foo ) ) ;
138
+ }
139
+
140
+ #[ test]
141
+ fn test_nested_non_exhaustive ( ) {
142
+ struct Foo ;
143
+
144
+ impl fmt:: Debug for Foo {
145
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
146
+ fmt. debug_struct ( "Foo" )
147
+ . field ( "bar" , & true )
148
+ . field ( "baz" , & format_args ! ( "{}/{}" , 10 , 20 ) )
149
+ . finish_non_exhaustive ( )
150
+ }
151
+ }
152
+
153
+ struct Bar ;
154
+
155
+ impl fmt:: Debug for Bar {
156
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
157
+ fmt. debug_struct ( "Bar" )
158
+ . field ( "foo" , & Foo )
159
+ . field ( "hello" , & "world" )
160
+ . finish_non_exhaustive ( )
161
+ }
162
+ }
163
+
164
+ assert_eq ! ( "Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \" world\" , .. }" ,
165
+ format!( "{:?}" , Bar ) ) ;
166
+ assert_eq ! (
167
+ "Bar {
168
+ foo: Foo {
169
+ bar: true,
170
+ baz: 10/20,
171
+ ..
172
+ },
173
+ hello: \" world\" ,
174
+ ..
175
+ }" ,
176
+ format!( "{:#?}" , Bar ) ) ;
177
+ }
178
+
96
179
}
97
180
98
181
mod debug_tuple {
0 commit comments