oysh/crates/oyster_parser/tests/it/cst.rs

146 lines
2 KiB
Rust
Raw Normal View History

2022-07-14 22:26:57 +00:00
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);
}