1
- use config:: { Config , ConfigError , File , FileFormat , Map , Value } ;
2
1
use serde_derive:: Deserialize ;
2
+ use snapbox:: { assert_data_eq, str} ;
3
+
4
+ use config:: { Config , ConfigError , File , FileFormat , Map , Value } ;
3
5
4
6
#[ test]
5
7
#[ cfg( feature = "json" ) ]
@@ -16,8 +18,10 @@ fn test_error_parse() {
16
18
. build ( ) ;
17
19
18
20
assert ! ( res. is_err( ) ) ;
19
- let err = res. unwrap_err ( ) ;
20
- assert_eq ! ( err. to_string( ) , "trailing comma at line 4 column 1" ) ;
21
+ assert_data_eq ! (
22
+ res. unwrap_err( ) . to_string( ) ,
23
+ str ![ "trailing comma at line 4 column 1" ]
24
+ ) ;
21
25
}
22
26
23
27
#[ test]
@@ -38,9 +42,9 @@ fn test_error_type() {
38
42
let res = c. get :: < bool > ( "boolean_s_parse" ) ;
39
43
40
44
assert ! ( res. is_err( ) ) ;
41
- assert_eq ! (
45
+ assert_data_eq ! (
42
46
res. unwrap_err( ) . to_string( ) ,
43
- format! ( "invalid type: string \ " fals\ " , expected a boolean for key `boolean_s_parse`" , )
47
+ str ! [ [ r# "invalid type: string "fals", expected a boolean for key `boolean_s_parse`"# ] ]
44
48
) ;
45
49
}
46
50
@@ -73,10 +77,10 @@ fn test_error_deser_whole() {
73
77
. build ( )
74
78
. unwrap ( ) ;
75
79
76
- let err = c. try_deserialize :: < Output > ( ) . unwrap_err ( ) . to_string ( ) ;
77
- assert_eq ! (
78
- err ,
79
- "invalid type: string \ " Torre di Pisa\ " , expected an integer for key `place.name`" ,
80
+ let res = c. try_deserialize :: < Output > ( ) ;
81
+ assert_data_eq ! (
82
+ res . unwrap_err ( ) . to_string ( ) ,
83
+ str ! [ [ r# "invalid type: string "Torre di Pisa", expected an integer for key `place.name`"# ] ]
80
84
) ;
81
85
}
82
86
@@ -99,9 +103,9 @@ fn test_error_type_detached() {
99
103
let res = value. try_deserialize :: < bool > ( ) ;
100
104
101
105
assert ! ( res. is_err( ) ) ;
102
- assert_eq ! (
106
+ assert_data_eq ! (
103
107
res. unwrap_err( ) . to_string( ) ,
104
- "invalid type: string \ " fals\ " , expected a boolean" . to_owned ( )
108
+ str ! [ [ r# "invalid type: string "fals", expected a boolean"# ] ]
105
109
) ;
106
110
}
107
111
@@ -123,9 +127,9 @@ fn test_error_type_get_bool() {
123
127
let res = c. get_bool ( "boolean_s_parse" ) ;
124
128
125
129
assert ! ( res. is_err( ) ) ;
126
- assert_eq ! (
130
+ assert_data_eq ! (
127
131
res. unwrap_err( ) . to_string( ) ,
128
- format! ( "invalid type: string \ " fals\ " , expected a boolean for key `boolean_s_parse`" , )
132
+ str ! [ [ r# "invalid type: string "fals", expected a boolean for key `boolean_s_parse`"# ] ]
129
133
) ;
130
134
}
131
135
@@ -147,9 +151,9 @@ fn test_error_type_get_table() {
147
151
let res = c. get_table ( "debug" ) ;
148
152
149
153
assert ! ( res. is_err( ) ) ;
150
- assert_eq ! (
154
+ assert_data_eq ! (
151
155
res. unwrap_err( ) . to_string( ) ,
152
- format! ( "invalid type: boolean `true`, expected a map for key `debug`" , )
156
+ str ! [ "invalid type: boolean `true`, expected a map for key `debug`" ]
153
157
) ;
154
158
}
155
159
@@ -171,9 +175,9 @@ fn test_error_type_get_array() {
171
175
let res = c. get_array ( "debug" ) ;
172
176
173
177
assert ! ( res. is_err( ) ) ;
174
- assert_eq ! (
178
+ assert_data_eq ! (
175
179
res. unwrap_err( ) . to_string( ) ,
176
- format! ( "invalid type: boolean `true`, expected an array for key `debug`" , )
180
+ str ! [ "invalid type: boolean `true`, expected an array for key `debug`" ]
177
181
) ;
178
182
}
179
183
@@ -189,17 +193,14 @@ fn test_error_enum_de() {
189
193
190
194
let on_v: Value = "on" . into ( ) ;
191
195
let on_d = on_v. try_deserialize :: < Diode > ( ) ;
192
- assert_eq ! (
196
+ assert_data_eq ! (
193
197
on_d. unwrap_err( ) . to_string( ) ,
194
- "enum Diode does not have variant constructor on" . to_owned ( )
198
+ str ! [ "enum Diode does not have variant constructor on" ]
195
199
) ;
196
200
197
201
let array_v: Value = vec ! [ 100 , 100 ] . into ( ) ;
198
202
let array_d = array_v. try_deserialize :: < Diode > ( ) ;
199
- assert_eq ! (
200
- array_d. unwrap_err( ) . to_string( ) ,
201
- "value of enum Diode should be represented by either string or table with exactly one key"
202
- ) ;
203
+ assert_data_eq ! ( array_d. unwrap_err( ) . to_string( ) , str ![ "value of enum Diode should be represented by either string or table with exactly one key" ] ) ;
203
204
204
205
let confused_v: Value = [
205
206
( "Brightness" . to_owned ( ) , 100 . into ( ) ) ,
@@ -210,10 +211,7 @@ fn test_error_enum_de() {
210
211
. collect :: < Map < String , Value > > ( )
211
212
. into ( ) ;
212
213
let confused_d = confused_v. try_deserialize :: < Diode > ( ) ;
213
- assert_eq ! (
214
- confused_d. unwrap_err( ) . to_string( ) ,
215
- "value of enum Diode should be represented by either string or table with exactly one key"
216
- ) ;
214
+ assert_data_eq ! ( confused_d. unwrap_err( ) . to_string( ) , str ![ "value of enum Diode should be represented by either string or table with exactly one key" ] ) ;
217
215
}
218
216
219
217
#[ test]
0 commit comments