diff options
| author | Brad Clawsie <brad@b7j0c.org> | 2026-11-25 14:18:46 -0600 |
|---|---|---|
| committer | Brad Clawsie <brad@b7j0c.org> | 2026-11-25 14:18:46 -0600 |
| commit | 7757056c7a43d4fbd85e3e817237d178bf6b1761 (patch) | |
| tree | 3c4fc7eac704b1237799b034d2d883aac8c1574c /learn_21/tests/parse_config.rs | |
| parent | 07e343541d0e60e34e582d43efd8cf573f8bb344 (diff) | |
fix: learn_21
Diffstat (limited to 'learn_21/tests/parse_config.rs')
| -rw-r--r-- | learn_21/tests/parse_config.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/learn_21/tests/parse_config.rs b/learn_21/tests/parse_config.rs index 8ca6626..6b963bc 100644 --- a/learn_21/tests/parse_config.rs +++ b/learn_21/tests/parse_config.rs @@ -11,20 +11,23 @@ fn test_ok() { assert!(parse_config(&ok1).is_ok_and(|x| x == Config{host:"myhost-012-".to_string(), port:65535, workers:usize::MAX})); - let ok2 = "port=1\n# comment\n host=my-host \n\n workers=1 \n"; + let ok2 = "port=1\n# comment\n host=my host \n\n workers=1 \n"; assert!(parse_config(ok2).is_ok_and(|x| x == - Config{host:"my-host".to_string(), port:1, workers:1})); + Config{host:"my host".to_string(), port:1, workers:1})); let ok3 = "port=1\n# comment\n host=my=host\n\n workers=1 \n"; assert!(parse_config(ok3).is_ok_and(|x| x == Config{host:"my=host".to_string(), port:1, workers:1})); + let ok4 = "\n# comment\n host= my-host \nport=1 \n workers=1 \n"; + assert!(parse_config(ok4).is_ok_and(|x| x == + Config{host:"my-host".to_string(), port:1, workers:1})); + } #[test] fn test_invalid_line() { let invalid0 = "host=hello\nport\nworkers=1\n"; - dbg!(parse_config(invalid0)); assert!(matches!( parse_config(invalid0), Err(ConfigError::InvalidLine(2)) @@ -69,10 +72,10 @@ fn test_duplicate_field() { #[test] fn test_invalid_value() { - let invalid0 = "host=hello...&&&\nport=1\nworkers=1\n"; + let invalid0 = "host= \nport=1\nworkers=1\n"; assert!(matches!( parse_config(invalid0), - Err(ConfigError::InvalidValue(s)) if s == "hello...&&&" + Err(ConfigError::InvalidValue(s)) if s == "" )); let invalid1 = "host=hello\nport=0\nworkers=1\n"; @@ -110,6 +113,18 @@ fn test_invalid_value() { parse_config(invalid6), Err(ConfigError::InvalidValue(s)) if s == "def" )); + + let invalid7 = "host=hello\nport=+1\nworkers=1\n"; + assert!(matches!( + parse_config(invalid7), + Err(ConfigError::InvalidValue(s)) if s == "+1" + )); + + let invalid8 = "host=hello\nport=1\nworkers=+1\n"; + assert!(matches!( + parse_config(invalid8), + Err(ConfigError::InvalidValue(s)) if s == "+1" + )); } #[test] |
