blob: e80a2f2fbc5bef79dc8d989bd6a8b505dbc54848 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
use config::Config;
#[test]
fn wrapping_u16() {
let c = Config::builder()
.add_source(config::File::from_str(
r#"
[settings]
port = 66000
"#,
config::FileFormat::Toml,
))
.build()
.unwrap();
// FIXME: Can't compare ConfigError, because Unexpected are private.
let _port_error = c.get::<u16>("settings.port").unwrap_err();
/*
assert!(matches!(
Err(ConfigError::invalid_type(None, config::Unexpected::U64(66000), "an unsigned 16 bit integer"),)
port_error
));
*/
}
#[test]
fn nonwrapping_u32() {
let c = Config::builder()
.add_source(config::File::from_str(
r#"
[settings]
port = 66000
"#,
config::FileFormat::Toml,
))
.build()
.unwrap();
let port: u32 = c.get("settings.port").unwrap();
assert_eq!(port, 66000);
}
#[test]
#[should_panic]
fn invalid_signedness() {
let c = Config::builder()
.add_source(config::File::from_str(
r#"
[settings]
port = -1
"#,
config::FileFormat::Toml,
))
.build()
.unwrap();
let _: u32 = c.get("settings.port").unwrap();
}
|