Brijesh's Git Server — bsh @ dbeb3fca578539e8c1c26f387d87f95341464c16

my own shell program

test: add tests for parser
Brijesh Wawdhane brijesh@wawdhane.com
Sat, 26 Oct 2024 16:47:31 +0530
commit

dbeb3fca578539e8c1c26f387d87f95341464c16

parent

4a881edf07a45d2a03f1f47ef5be6886acc8c883

3 files changed, 28 insertions(+), 1 deletions(-)

jump to
M src/main.rssrc/main.rs

@@ -6,7 +6,6 @@ mod executor;

mod parser; mod shell; mod tests; -mod utils; fn main() -> Result<(), error::ShellError> { let mut shell = shell::Shell::new();
A src/tests/mod.rs

@@ -0,0 +1,1 @@

+mod parser_test;
A src/tests/parser_test.rs

@@ -0,0 +1,27 @@

+#[cfg(test)] +mod tests { + use crate::parser; + + #[test] + fn test_parse_simple_command() { + let input = "echo hello"; + let parsed = parser::parse(input).expect("Failed to parse command"); + assert_eq!(parsed.command, "echo"); + assert_eq!(parsed.args, vec!["hello"]); + } + + #[test] + fn test_parse_quoted_argument() { + let input = "echo 'hello world'"; + let parsed = parser::parse(input).expect("Failed to parse command"); + assert_eq!(parsed.command, "echo"); + assert_eq!(parsed.args, vec!["hello world"]); + } + + #[test] + fn test_parse_empty_input() { + let input = ""; + let parsed = parser::parse(input); + assert!(parsed.is_err(), "Empty input should result in error"); + } +}