oysh/crates/oyster_parser/tests/it/cst.rs
Charlotte Meyer 4e1a835ddc feat: add command substitutions with ()
This requires PreparedCommand's to work with OsStrings rather than
Strings.

Acked-by: cpli
Acked-by: ElKowar
2022-10-28 08:12:25 +00:00

191 lines
2.7 KiB
Rust

use insta::assert_debug_snapshot as assert_snapshot;
use oyster_parser::ParseTree;
fn parse(s: &str) -> ParseTree {
ParseTree::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);
}