Skip to content
Snippets Groups Projects
Commit f296610c authored by aalbert's avatar aalbert
Browse files

Resolve "panic when entering "a"" ✨️

Closes #71 🐔️👍️
Approved-by: default avataraalbert <augustin.albert@bleu-azure.fr>

🦀️🍰🦀️🍰🦀️🍰

* feat(proost): add test for is_command behavior with 1 letter

* fix(proost): add missing boundary check
parent 8b20ac80
No related branches found
No related tags found
Loading
Pipeline #11939 canceled with stages
in 1 minute and 19 seconds
...@@ -78,12 +78,25 @@ fn main() -> Result<'static, ()> { ...@@ -78,12 +78,25 @@ fn main() -> Result<'static, ()> {
} }
fn is_command(input: &str) -> bool { fn is_command(input: &str) -> bool {
input.chars().position(|c| !c.is_whitespace()).map(|pos| input[pos..pos + 2] != *"//").unwrap_or_else(|| false) input
.chars()
.position(|c| !c.is_whitespace())
.map(|pos| input.len() < 2 || input[pos..pos + 2] != *"//")
.unwrap_or_else(|| false)
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test]
fn is_command_no_crash() {
assert!(!super::is_command(""));
assert!(super::is_command("a"));
assert!(super::is_command("aa"));
assert!(super::is_command("aaa"));
assert!(super::is_command("aaaa"));
}
#[test] #[test]
fn is_command_false() { fn is_command_false() {
assert!(!super::is_command(" ")); assert!(!super::is_command(" "));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment