Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,6 @@ fn unlabeled_alternation_three_items() {
"#);
}

#[test]
fn upper_ident_in_alternation_not_followed_by_colon() {
let input = indoc! {r#"
[(Expr) (Statement)]
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: undefined reference: `Expr`
|
1 | [(Expr) (Statement)]
| ^^^^ undefined reference: `Expr`
error: undefined reference: `Statement`
|
1 | [(Expr) (Statement)]
| ^^^^^^^^^ undefined reference: `Statement`
"#);
}

#[test]
fn tagged_alternation_simple() {
let input = indoc! {r#"
Expand Down Expand Up @@ -581,24 +561,6 @@ fn tagged_alternation_with_sequence() {
"#);
}

#[test]
fn mixed_tagged_and_untagged() {
let input = indoc! {r#"
[Tagged: (a) (b) Another: (c)]
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: mixed tagged and untagged branches in alternation
|
1 | [Tagged: (a) (b) Another: (c)]
| ------ ^^^ mixed tagged and untagged branches in alternation
| |
| tagged branch here
"#);
}

#[test]
fn tagged_alternation_with_nested_alternation() {
let input = indoc! {r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,3 @@ fn anchor_in_sequence() {
BraceClose "}"
"#);
}

#[test]
fn capture_space_after_dot_is_anchor() {
let input = indoc! {r#"
(identifier) @foo . (other)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: unnamed definition must be last in file; add a name: `Name = (identifier) @foo`
|
1 | (identifier) @foo . (other)
| ^^^^^^^^^^^^^^^^^ unnamed definition must be last in file; add a name: `Name = (identifier) @foo`
error: unnamed definition must be last in file; add a name: `Name = .`
|
1 | (identifier) @foo . (other)
| ^ unnamed definition must be last in file; add a name: `Name = .`
"#);
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,58 +367,6 @@ fn named_def_with_type_annotation() {
"#);
}

#[test]
fn upper_ident_not_followed_by_equals_is_expression() {
let input = indoc! {r#"
(Expr)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: undefined reference: `Expr`
|
1 | (Expr)
| ^^^^ undefined reference: `Expr`
"#);
}

#[test]
fn bare_upper_ident_not_followed_by_equals_is_error() {
let input = indoc! {r#"
Expr
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: bare identifier not allowed; nodes must be enclosed in parentheses, e.g., (identifier)
|
1 | Expr
| ^^^^ bare identifier not allowed; nodes must be enclosed in parentheses, e.g., (identifier)
"#);
}

#[test]
fn named_def_missing_equals() {
let input = indoc! {r#"
Expr (identifier)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: bare identifier not allowed; nodes must be enclosed in parentheses, e.g., (identifier)
|
1 | Expr (identifier)
| ^^^^ bare identifier not allowed; nodes must be enclosed in parentheses, e.g., (identifier)
error: unnamed definition must be last in file; add a name: `Name = Expr`
|
1 | Expr (identifier)
| ^^^^ unnamed definition must be last in file; add a name: `Name = Expr`
"#);
}

#[test]
fn unnamed_def_allowed_as_last() {
let input = indoc! {r#"
Expand Down Expand Up @@ -451,43 +399,3 @@ fn unnamed_def_allowed_as_last() {
ParenClose ")"
"#);
}

#[test]
fn unnamed_def_not_allowed_in_middle() {
let input = indoc! {r#"
(first)
Expr = (identifier)
(last)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: unnamed definition must be last in file; add a name: `Name = (first)`
|
1 | (first)
| ^^^^^^^ unnamed definition must be last in file; add a name: `Name = (first)`
"#);
}

#[test]
fn multiple_unnamed_defs_errors_for_all_but_last() {
let input = indoc! {r#"
(first)
(second)
(third)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: unnamed definition must be last in file; add a name: `Name = (first)`
|
1 | (first)
| ^^^^^^^ unnamed definition must be last in file; add a name: `Name = (first)`
error: unnamed definition must be last in file; add a name: `Name = (second)`
|
2 | (second)
| ^^^^^^^^ unnamed definition must be last in file; add a name: `Name = (second)`
"#);
}
19 changes: 10 additions & 9 deletions crates/plotnik-lib/src/ast/parser/tests/grammar/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod alternations;
mod anchors;
mod captures;
mod definitions;
mod fields;
mod nodes;
mod quantifiers;
mod sequences;
mod special;
mod alternations_tests;
mod anchors_tests;
mod captures_tests;
mod definitions_tests;
mod fields_tests;
mod nodes_tests;
mod quantifiers_tests;
mod sequences_tests;
mod special_tests;
mod trivia_tests;
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,6 @@ fn sibling_children() {
"#);
}

#[test]
fn multiple_expressions() {
let input = indoc! {r#"
(identifier)
(string)
(number)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: unnamed definition must be last in file; add a name: `Name = (identifier)`
|
1 | (identifier)
| ^^^^^^^^^^^^ unnamed definition must be last in file; add a name: `Name = (identifier)`
error: unnamed definition must be last in file; add a name: `Name = (string)`
|
2 | (string)
| ^^^^^^^^ unnamed definition must be last in file; add a name: `Name = (string)`
"#);
}

#[test]
fn wildcard() {
let input = indoc! {r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ fn comment_preserved() {
"#);
}

#[test]
fn multiline() {
let input = indoc! {r#"
(a)

(b)
"#};

let query = Query::new(input).unwrap();
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_errors(), @r#"
error: unnamed definition must be last in file; add a name: `Name = (a)`
|
1 | (a)
| ^^^ unnamed definition must be last in file; add a name: `Name = (a)`
"#);
}

#[test]
fn comment_inside_expression() {
let input = indoc! {r#"
Expand Down
1 change: 0 additions & 1 deletion crates/plotnik-lib/src/ast/parser/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod grammar;
mod recovery;
mod trivia;

// JSON serialization tests for the error API
mod json_serialization {
Expand Down
Loading