@@ -38,7 +38,70 @@ fn test_file() {
38
38
struct AsciiCode ( i8 ) ;
39
39
40
40
let c = Config :: builder ( )
41
- . add_source ( File :: new ( "tests/Settings" , FileFormat :: Toml ) )
41
+ . add_source ( File :: from_str (
42
+ r#"
43
+ debug = true
44
+ debug_s = "true"
45
+ production = false
46
+ production_s = "false"
47
+
48
+ code = 53
49
+
50
+ # errors
51
+ boolean_s_parse = "fals"
52
+
53
+ # For override tests
54
+ FOO="FOO should be overridden"
55
+ bar="I am bar"
56
+
57
+ arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
58
+ quarks = ["up", "down", "strange", "charm", "bottom", "top"]
59
+
60
+ [diodes]
61
+ green = "off"
62
+
63
+ [diodes.red]
64
+ brightness = 100
65
+
66
+ [diodes.blue]
67
+ blinking = [300, 700]
68
+
69
+ [diodes.white.pattern]
70
+ name = "christmas"
71
+ inifinite = true
72
+
73
+ [[items]]
74
+ name = "1"
75
+
76
+ [[items]]
77
+ name = "2"
78
+
79
+ [place]
80
+ number = 1
81
+ name = "Torre di Pisa"
82
+ longitude = 43.7224985
83
+ latitude = 10.3970522
84
+ favorite = false
85
+ reviews = 3866
86
+ rating = 4.5
87
+
88
+ [place.creator]
89
+ name = "John Smith"
90
+ username = "jsmith"
91
+ email = "jsmith@localhost"
92
+
93
+ [proton]
94
+ up = 2
95
+ down = 1
96
+
97
+ [divisors]
98
+ 1 = 1
99
+ 2 = 2
100
+ 4 = 3
101
+ 5 = 2
102
+ "# ,
103
+ FileFormat :: Toml ,
104
+ ) )
42
105
. build ( )
43
106
. unwrap ( ) ;
44
107
@@ -81,14 +144,20 @@ fn test_file() {
81
144
#[ test]
82
145
fn test_error_parse ( ) {
83
146
let res = Config :: builder ( )
84
- . add_source ( File :: new ( "tests/Settings-invalid" , FileFormat :: Toml ) )
147
+ . add_source ( File :: from_str (
148
+ r#"
149
+ ok = true
150
+ error = tru
151
+ "# ,
152
+ FileFormat :: Toml ,
153
+ ) )
85
154
. build ( ) ;
86
155
87
156
assert ! ( res. is_err( ) ) ;
88
157
assert ! ( res
89
158
. unwrap_err( )
90
159
. to_string( )
91
- . contains( "TOML parse error at line 2 , column 9" ) ) ;
160
+ . contains( "TOML parse error at line 3 , column 9" ) ) ;
92
161
}
93
162
94
163
#[ test]
@@ -108,7 +177,70 @@ fn test_override_uppercase_value_for_struct() {
108
177
std:: env:: set_var ( "APP_FOO" , "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE" ) ;
109
178
110
179
let cfg = Config :: builder ( )
111
- . add_source ( File :: new ( "tests/Settings.toml" , FileFormat :: Toml ) )
180
+ . add_source ( File :: from_str (
181
+ r#"
182
+ debug = true
183
+ debug_s = "true"
184
+ production = false
185
+ production_s = "false"
186
+
187
+ code = 53
188
+
189
+ # errors
190
+ boolean_s_parse = "fals"
191
+
192
+ # For override tests
193
+ FOO="FOO should be overridden"
194
+ bar="I am bar"
195
+
196
+ arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
197
+ quarks = ["up", "down", "strange", "charm", "bottom", "top"]
198
+
199
+ [diodes]
200
+ green = "off"
201
+
202
+ [diodes.red]
203
+ brightness = 100
204
+
205
+ [diodes.blue]
206
+ blinking = [300, 700]
207
+
208
+ [diodes.white.pattern]
209
+ name = "christmas"
210
+ inifinite = true
211
+
212
+ [[items]]
213
+ name = "1"
214
+
215
+ [[items]]
216
+ name = "2"
217
+
218
+ [place]
219
+ number = 1
220
+ name = "Torre di Pisa"
221
+ longitude = 43.7224985
222
+ latitude = 10.3970522
223
+ favorite = false
224
+ reviews = 3866
225
+ rating = 4.5
226
+
227
+ [place.creator]
228
+ name = "John Smith"
229
+ username = "jsmith"
230
+ email = "jsmith@localhost"
231
+
232
+ [proton]
233
+ up = 2
234
+ down = 1
235
+
236
+ [divisors]
237
+ 1 = 1
238
+ 2 = 2
239
+ 4 = 3
240
+ 5 = 2
241
+ "# ,
242
+ FileFormat :: Toml ,
243
+ ) )
112
244
. add_source ( config:: Environment :: with_prefix ( "APP" ) . separator ( "_" ) )
113
245
. build ( )
114
246
. unwrap ( ) ;
@@ -149,7 +281,70 @@ fn test_override_lowercase_value_for_struct() {
149
281
std:: env:: set_var ( "config_bar" , "I have been overridden_with_lower_case" ) ;
150
282
151
283
let cfg = Config :: builder ( )
152
- . add_source ( File :: new ( "tests/Settings.toml" , FileFormat :: Toml ) )
284
+ . add_source ( File :: from_str (
285
+ r#"
286
+ debug = true
287
+ debug_s = "true"
288
+ production = false
289
+ production_s = "false"
290
+
291
+ code = 53
292
+
293
+ # errors
294
+ boolean_s_parse = "fals"
295
+
296
+ # For override tests
297
+ FOO="FOO should be overridden"
298
+ bar="I am bar"
299
+
300
+ arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
301
+ quarks = ["up", "down", "strange", "charm", "bottom", "top"]
302
+
303
+ [diodes]
304
+ green = "off"
305
+
306
+ [diodes.red]
307
+ brightness = 100
308
+
309
+ [diodes.blue]
310
+ blinking = [300, 700]
311
+
312
+ [diodes.white.pattern]
313
+ name = "christmas"
314
+ inifinite = true
315
+
316
+ [[items]]
317
+ name = "1"
318
+
319
+ [[items]]
320
+ name = "2"
321
+
322
+ [place]
323
+ number = 1
324
+ name = "Torre di Pisa"
325
+ longitude = 43.7224985
326
+ latitude = 10.3970522
327
+ favorite = false
328
+ reviews = 3866
329
+ rating = 4.5
330
+
331
+ [place.creator]
332
+ name = "John Smith"
333
+ username = "jsmith"
334
+ email = "jsmith@localhost"
335
+
336
+ [proton]
337
+ up = 2
338
+ down = 1
339
+
340
+ [divisors]
341
+ 1 = 1
342
+ 2 = 2
343
+ 4 = 3
344
+ 5 = 2
345
+ "# ,
346
+ FileFormat :: Toml ,
347
+ ) )
153
348
. add_source ( config:: Environment :: with_prefix ( "config" ) . separator ( "_" ) )
154
349
. build ( )
155
350
. unwrap ( ) ;
@@ -172,7 +367,12 @@ fn test_override_uppercase_value_for_enums() {
172
367
std:: env:: set_var ( "APPS_BAR" , "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE" ) ;
173
368
174
369
let cfg = Config :: builder ( )
175
- . add_source ( File :: new ( "tests/Settings-enum-test.toml" , FileFormat :: Toml ) )
370
+ . add_source ( File :: from_str (
371
+ r#"
372
+ bar = "bar is a lowercase param"
373
+ "# ,
374
+ FileFormat :: Toml ,
375
+ ) )
176
376
. add_source ( config:: Environment :: with_prefix ( "APPS" ) . separator ( "_" ) )
177
377
. build ( )
178
378
. unwrap ( ) ;
@@ -195,7 +395,12 @@ fn test_override_lowercase_value_for_enums() {
195
395
std:: env:: set_var ( "test_bar" , "I have been overridden_with_lower_case" ) ;
196
396
197
397
let cfg = Config :: builder ( )
198
- . add_source ( File :: new ( "tests/Settings-enum-test.toml" , FileFormat :: Toml ) )
398
+ . add_source ( File :: from_str (
399
+ r#"
400
+ bar = "bar is a lowercase param"
401
+ "# ,
402
+ FileFormat :: Toml ,
403
+ ) )
199
404
. add_source ( config:: Environment :: with_prefix ( "test" ) . separator ( "_" ) )
200
405
. build ( )
201
406
. unwrap ( ) ;
@@ -214,7 +419,7 @@ fn toml() {
214
419
. add_source ( File :: from_str (
215
420
r#"
216
421
toml_datetime = 2017-05-11T14:55:15Z
217
- "#,
422
+ "# ,
218
423
FileFormat :: Toml ,
219
424
) )
220
425
. build ( )
0 commit comments