Skip to content

Commit e316732

Browse files
committed
test(json5): Reduce the scope of fixtures
1 parent c1b4ca2 commit e316732

File tree

1 file changed

+107
-14
lines changed

1 file changed

+107
-14
lines changed

tests/testsuite/file_json5.rs

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![cfg(feature = "json5")]
22

3-
use std::path::PathBuf;
4-
53
use chrono::{DateTime, TimeZone, Utc};
64
use float_cmp::ApproxEqUlps;
75
use serde_derive::Deserialize;
@@ -32,7 +30,33 @@ fn test_file() {
3230
}
3331

3432
let c = Config::builder()
35-
.add_source(File::new("tests/Settings", FileFormat::Json5))
33+
.add_source(File::from_str(
34+
r#"
35+
{
36+
// c
37+
/* c */
38+
debug: true,
39+
production: false,
40+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,],
41+
place: {
42+
name: 'Torre di Pisa',
43+
longitude: 43.7224985,
44+
latitude: 10.3970522,
45+
favorite: false,
46+
reviews: 3866,
47+
rating: 4.5,
48+
creator: {
49+
name: "John Smith",
50+
"username": "jsmith",
51+
"email": "jsmith@localhost",
52+
}
53+
},
54+
FOO: "FOO should be overridden",
55+
bar: "I am bar",
56+
}
57+
"#,
58+
FileFormat::Json5,
59+
))
3660
.build()
3761
.unwrap();
3862

@@ -73,18 +97,21 @@ fn test_file() {
7397
#[test]
7498
fn test_error_parse() {
7599
let res = Config::builder()
76-
.add_source(File::new("tests/Settings-invalid", FileFormat::Json5))
100+
.add_source(File::from_str(
101+
r#"
102+
{
103+
ok: true
104+
error
105+
}
106+
"#,
107+
FileFormat::Json5,
108+
))
77109
.build();
78110

79-
let path_with_extension: PathBuf = ["tests", "Settings-invalid.json5"].iter().collect();
80-
81111
assert!(res.is_err());
82112
assert_eq!(
83113
res.unwrap_err().to_string(),
84-
format!(
85-
" --> 2:7\n |\n2 | ok: true\n | ^---\n |\n = expected null in {}",
86-
path_with_extension.display()
87-
)
114+
format!(" --> 3:7\n |\n3 | ok: true\n | ^---\n |\n = expected null",)
88115
);
89116
}
90117

@@ -105,7 +132,33 @@ fn test_override_uppercase_value_for_struct() {
105132
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
106133

107134
let cfg = Config::builder()
108-
.add_source(File::new("tests/Settings", FileFormat::Json5))
135+
.add_source(File::from_str(
136+
r#"
137+
{
138+
// c
139+
/* c */
140+
debug: true,
141+
production: false,
142+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,],
143+
place: {
144+
name: 'Torre di Pisa',
145+
longitude: 43.7224985,
146+
latitude: 10.3970522,
147+
favorite: false,
148+
reviews: 3866,
149+
rating: 4.5,
150+
creator: {
151+
name: "John Smith",
152+
"username": "jsmith",
153+
"email": "jsmith@localhost",
154+
}
155+
},
156+
FOO: "FOO should be overridden",
157+
bar: "I am bar",
158+
}
159+
"#,
160+
FileFormat::Json5,
161+
))
109162
.add_source(config::Environment::with_prefix("APP").separator("_"))
110163
.build()
111164
.unwrap();
@@ -146,7 +199,33 @@ fn test_override_lowercase_value_for_struct() {
146199
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
147200

148201
let cfg = Config::builder()
149-
.add_source(File::new("tests/Settings", FileFormat::Json5))
202+
.add_source(File::from_str(
203+
r#"
204+
{
205+
// c
206+
/* c */
207+
debug: true,
208+
production: false,
209+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,],
210+
place: {
211+
name: 'Torre di Pisa',
212+
longitude: 43.7224985,
213+
latitude: 10.3970522,
214+
favorite: false,
215+
reviews: 3866,
216+
rating: 4.5,
217+
creator: {
218+
name: "John Smith",
219+
"username": "jsmith",
220+
"email": "jsmith@localhost",
221+
}
222+
},
223+
FOO: "FOO should be overridden",
224+
bar: "I am bar",
225+
}
226+
"#,
227+
FileFormat::Json5,
228+
))
150229
.add_source(config::Environment::with_prefix("config").separator("_"))
151230
.build()
152231
.unwrap();
@@ -169,7 +248,14 @@ fn test_override_uppercase_value_for_enums() {
169248
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
170249

171250
let cfg = Config::builder()
172-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Json5))
251+
.add_source(File::from_str(
252+
r#"
253+
{
254+
bar: "bar is a lowercase param",
255+
}
256+
"#,
257+
FileFormat::Json5,
258+
))
173259
.add_source(config::Environment::with_prefix("APPS").separator("_"))
174260
.build()
175261
.unwrap();
@@ -191,7 +277,14 @@ fn test_override_lowercase_value_for_enums() {
191277
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
192278

193279
let cfg = Config::builder()
194-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Json5))
280+
.add_source(File::from_str(
281+
r#"
282+
{
283+
bar: "bar is a lowercase param",
284+
}
285+
"#,
286+
FileFormat::Json5,
287+
))
195288
.add_source(config::Environment::with_prefix("test").separator("_"))
196289
.build()
197290
.unwrap();

0 commit comments

Comments
 (0)