internal: add tests for patterns

This commit is contained in:
Aleksey Kladov 2021-12-30 14:20:35 +03:00
parent 3d63abf1d8
commit 5ca83a5fb3

View file

@ -21,12 +21,22 @@ fn stmt() {
check_prefix(PrefixEntryPoint::Stmt, "92; fn", "92"); check_prefix(PrefixEntryPoint::Stmt, "92; fn", "92");
check_prefix(PrefixEntryPoint::Stmt, "let _ = 92; 1", "let _ = 92"); check_prefix(PrefixEntryPoint::Stmt, "let _ = 92; 1", "let _ = 92");
check_prefix(PrefixEntryPoint::Stmt, "pub fn f() {} = 92", "pub fn f() {}"); check_prefix(PrefixEntryPoint::Stmt, "pub fn f() {} = 92", "pub fn f() {}");
check_prefix(PrefixEntryPoint::Stmt, "struct S;;", "struct S;");
check_prefix(PrefixEntryPoint::Stmt, "fn f() {};", "fn f() {}");
check_prefix(PrefixEntryPoint::Stmt, ";;;", ";"); check_prefix(PrefixEntryPoint::Stmt, ";;;", ";");
check_prefix(PrefixEntryPoint::Stmt, "+", "+"); check_prefix(PrefixEntryPoint::Stmt, "+", "+");
check_prefix(PrefixEntryPoint::Stmt, "@", "@"); check_prefix(PrefixEntryPoint::Stmt, "@", "@");
check_prefix(PrefixEntryPoint::Stmt, "loop {} - 1", "loop {}"); check_prefix(PrefixEntryPoint::Stmt, "loop {} - 1", "loop {}");
} }
#[test]
fn pat() {
check_prefix(PrefixEntryPoint::Pat, "x y", "x");
check_prefix(PrefixEntryPoint::Pat, "fn f() {}", "fn");
// FIXME: this one is wrong
check_prefix(PrefixEntryPoint::Pat, ".. ..", ".. ..");
}
fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) { fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) {
let lexed = LexedStr::new(input); let lexed = LexedStr::new(input);
let input = lexed.to_input(); let input = lexed.to_input();