From a78ea17c782fa14c47dd3ac4cd46e62364764eea Mon Sep 17 00:00:00 2001 From: Yihong Zhang Date: Tue, 30 Jul 2024 14:55:15 -0700 Subject: [PATCH] add tests --- src/main.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7f71f1d7..28b410b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,7 @@ struct Args { max_calls_per_function: usize, } -// Takes a multi-line string, processes the first command, and returns the rest of the string +// test if the current command should be evaluated fn should_eval(curr_cmd: &str) -> bool { let mut count = 0; let mut indices = curr_cmd.chars(); @@ -249,3 +249,38 @@ fn main() { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_should_eval() { + #[rustfmt::skip] + let test_cases = vec![ + vec![ + "(extract", + "\"1", + ")", + "(", + ")))", + "\"", + ";; )", + ")" + ], + vec![ + "(extract 1) (extract", + "2) (", + "extract 3) (extract 4) ;;;; (" + ]]; + for test in test_cases { + let mut cmd_buffer = String::new(); + for (i, line) in test.iter().enumerate() { + cmd_buffer.push_str(line); + cmd_buffer.push('\n'); + dbg!(i, &cmd_buffer, should_eval(&cmd_buffer)); + assert_eq!(should_eval(&cmd_buffer), i == test.len() - 1); + } + } + } +}