Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/tests/top_entries.rs')
-rw-r--r--crates/parser/src/tests/top_entries.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/crates/parser/src/tests/top_entries.rs b/crates/parser/src/tests/top_entries.rs
index dcf61b6aca..24e41b46f8 100644
--- a/crates/parser/src/tests/top_entries.rs
+++ b/crates/parser/src/tests/top_entries.rs
@@ -53,6 +53,13 @@ fn source_file() {
fn macro_stmt() {
check(
TopEntryPoint::MacroStmts,
+ "",
+ expect![[r#"
+ MACRO_STMTS
+ "#]],
+ );
+ check(
+ TopEntryPoint::MacroStmts,
"#!/usr/bin/rust",
expect![[r##"
MACRO_STMTS
@@ -96,6 +103,13 @@ fn macro_stmt() {
fn macro_items() {
check(
TopEntryPoint::MacroItems,
+ "",
+ expect![[r#"
+ MACRO_ITEMS
+ "#]],
+ );
+ check(
+ TopEntryPoint::MacroItems,
"#!/usr/bin/rust",
expect![[r##"
MACRO_ITEMS
@@ -133,6 +147,14 @@ fn macro_items() {
fn macro_pattern() {
check(
TopEntryPoint::Pattern,
+ "",
+ expect![[r#"
+ ERROR
+ error 0: expected pattern
+ "#]],
+ );
+ check(
+ TopEntryPoint::Pattern,
"Some(_)",
expect![[r#"
TUPLE_STRUCT_PAT
@@ -179,6 +201,15 @@ fn macro_pattern() {
fn type_() {
check(
TopEntryPoint::Type,
+ "",
+ expect![[r#"
+ ERROR
+ error 0: expected type
+ "#]],
+ );
+
+ check(
+ TopEntryPoint::Type,
"Option<!>",
expect![[r#"
PATH_TYPE
@@ -224,6 +255,54 @@ fn type_() {
);
}
+#[test]
+fn expr() {
+ check(
+ TopEntryPoint::Expr,
+ "",
+ expect![[r#"
+ ERROR
+ error 0: expected expression
+ "#]],
+ );
+ check(
+ TopEntryPoint::Expr,
+ "2 + 2 == 5",
+ expect![[r#"
+ BIN_EXPR
+ BIN_EXPR
+ LITERAL
+ INT_NUMBER "2"
+ WHITESPACE " "
+ PLUS "+"
+ WHITESPACE " "
+ LITERAL
+ INT_NUMBER "2"
+ WHITESPACE " "
+ EQ2 "=="
+ WHITESPACE " "
+ LITERAL
+ INT_NUMBER "5"
+ "#]],
+ );
+ check(
+ TopEntryPoint::Expr,
+ "let _ = 0;",
+ expect![[r#"
+ ERROR
+ LET_KW "let"
+ WHITESPACE " "
+ UNDERSCORE "_"
+ WHITESPACE " "
+ EQ "="
+ WHITESPACE " "
+ INT_NUMBER "0"
+ SEMICOLON ";"
+ error 0: expected expression
+ "#]],
+ );
+}
+
#[track_caller]
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
let (parsed, _errors) = super::parse(entry, input);