Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang committed Jul 30, 2024
1 parent edcd1bc commit a78ea17
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit a78ea17

Please sign in to comment.