blob: 8fe8b43f0d43b5c675574e6d763cdeb171008220 (
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
|
use std::convert::TryFrom;
use gix_config_value::Boolean;
use crate::b;
#[test]
fn from_str_false() -> crate::Result {
assert!(!Boolean::try_from(b("no"))?.0);
assert!(!Boolean::try_from(b("off"))?.0);
assert!(!Boolean::try_from(b("false"))?.0);
assert!(!Boolean::try_from(b("0"))?.0);
assert!(!Boolean::try_from(b(""))?.0);
Ok(())
}
#[test]
fn from_str_true() -> crate::Result {
assert_eq!(Boolean::try_from(b("yes")).map(Into::into), Ok(true));
assert_eq!(Boolean::try_from(b("on")), Ok(Boolean(true)));
assert_eq!(Boolean::try_from(b("true")), Ok(Boolean(true)));
assert!(Boolean::try_from(b("1"))?.0);
assert!(Boolean::try_from(b("+10"))?.0);
assert!(Boolean::try_from(b("-1"))?.0);
Ok(())
}
#[test]
fn ignores_case() {
// Random subset
for word in &["no", "yes", "on", "off", "true", "false"] {
let first: bool = Boolean::try_from(b(word)).unwrap().into();
let second: bool = Boolean::try_from(b(&word.to_uppercase())).unwrap().into();
assert_eq!(first, second);
}
}
#[test]
fn from_str_err() {
assert!(Boolean::try_from(b("yesn't")).is_err());
assert!(Boolean::try_from(b("yesno")).is_err());
}
|