Impl: Check for wrong input characters
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -1,7 +1,5 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
@@ -87,7 +85,12 @@ fn parse_playfield(field: &String, field_size: usize) -> Playfield {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
field.value = Some(char_field.parse().unwrap());
|
field.value = Some(char_field.parse().unwrap_or_else(|char_field| {
|
||||||
|
panic!(
|
||||||
|
"Input must contain only digits followed by space. Disallowed character: {}",
|
||||||
|
char_field
|
||||||
|
)
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "Input must have dimension of size 2x2")]
|
#[should_panic(expected = "Input must have dimension of size 3x3")]
|
||||||
fn test_parse_field_too_short_input() {
|
fn test_parse_field_too_short_input() {
|
||||||
let input = "1 2 3";
|
let input = "1 2 3";
|
||||||
let field_size = 3;
|
let field_size = 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user