use insta::assert_debug_snapshot as assert_snapshot; use oyster_parser::{ast, ParseError}; fn parse(s: &str) -> Result { ast::Code::try_from(s) } #[test] fn empty() { let source = ""; let actual = parse(source); assert_snapshot!(actual); } #[test] fn word() { let source = "word"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn word_with_escape() { let source = r"hello\#world"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn unicode() { let source = "谚语"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn simple_command() { let source = "echo hi"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn semicolon() { let source = "hello; hi"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn comment() { let source = r"# a # b"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn inline_comment() { let source = "whoami # hello"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn pipeline() { let source = "whoami | cat"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn multiline_pipeline() { let source = r"whoami | wc -l"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn comment_in_pipeline() { let source = r"whoami | # comment wc -l"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn reject_leading_pipe() { let source = r"whoami | cat"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn reject_trailing_pipe() { let source = "whoami |"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn reject_pipe_semicolon() { let source = "whoami | ; cat"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn reject_double_pipe() { let source = "whoami | | cat"; let actual = parse(source); assert_snapshot!(actual); } #[test] fn double_quote_string() { let source = r#""hello world""#; let actual = parse(source); assert_snapshot!(actual); } #[test] fn escaped_char_in_double_quotes() { let source = r#""hello \" world""#; let actual = parse(source); assert_snapshot!(actual); } #[test] fn unterminated_double_quotes() { let source = r#""hello world"#; let actual = parse(source); assert_snapshot!(actual); } #[test] fn command_substitution() { let source = r#"echo (whoami)"#; let actual = parse(source); assert_snapshot!(actual); } #[test] fn quoted_command_substitution() { let source = r#"echo "(whoami) ""#; let actual = parse(source); assert_snapshot!(actual); }