Implemented case statements

This commit is contained in:
2025-03-19 02:16:53 -04:00
parent 653a5fe344
commit 10af34b0d7
12 changed files with 2809 additions and 100 deletions

View File

@@ -138,3 +138,49 @@ done";
insta::assert_debug_snapshot!(nodes)
}
#[test]
fn parse_case_simple() {
let input = "case foo in foo) bar;; bar) foo;; biz) baz;; esac";
let tk_stream: Vec<_> = LexStream::new(Rc::new(input.to_string()), LexFlags::empty())
.map(|tk| tk.unwrap())
.collect();
let nodes: Vec<_> = ParseStream::new(tk_stream).collect();
insta::assert_debug_snapshot!(nodes)
}
#[test]
fn parse_case_multiline() {
let input = "case foo in
foo) bar
;;
bar) foo
;;
biz) baz
;;
esac";
let tk_stream: Vec<_> = LexStream::new(Rc::new(input.to_string()), LexFlags::empty())
.map(|tk| tk.unwrap())
.collect();
let nodes: Vec<_> = ParseStream::new(tk_stream).collect();
insta::assert_debug_snapshot!(nodes)
}
#[test]
fn parse_case_nested() {
let input = "case foo in
foo) if true; then
echo foo
fi
;;
bar) if false; then
echo bar
fi
;;
esac";
let tk_stream: Vec<_> = LexStream::new(Rc::new(input.to_string()), LexFlags::empty())
.map(|tk| tk.unwrap())
.collect();
let nodes: Vec<_> = ParseStream::new(tk_stream).collect();
insta::assert_debug_snapshot!(nodes)
}