diff --git a/crates/plotnik-lib/src/diagnostics/message.rs b/crates/plotnik-lib/src/diagnostics/message.rs index f29853fa..e700d1ea 100644 --- a/crates/plotnik-lib/src/diagnostics/message.rs +++ b/crates/plotnik-lib/src/diagnostics/message.rs @@ -74,7 +74,7 @@ pub enum DiagnosticKind { InvalidChildType, // Often consequences of earlier errors - UnnamedDefNotLast, + UnnamedDef, } impl DiagnosticKind { @@ -119,7 +119,7 @@ impl DiagnosticKind { /// Consequence errors - often caused by earlier parse errors. /// These get suppressed when any root-cause or structural error exists. pub fn is_consequence_error(&self) -> bool { - matches!(self, Self::UnnamedDefNotLast) + matches!(self, Self::UnnamedDef) } /// Base message for this diagnostic kind, used when no custom message is provided. @@ -189,7 +189,7 @@ impl DiagnosticKind { Self::InvalidChildType => "node type not valid as child", // Structural - Self::UnnamedDefNotLast => "only the last definition can be unnamed", + Self::UnnamedDef => "definitions must be named", } } @@ -229,8 +229,8 @@ impl DiagnosticKind { "type annotations use `::`, not `:` — {}".to_string() } - // Named def ordering - Self::UnnamedDefNotLast => "only the last definition can be unnamed — {}".to_string(), + // Named def + Self::UnnamedDef => "definitions must be named — {}".to_string(), // Standard pattern: fallback + context _ => format!("{}; {{}}", self.fallback_message()), diff --git a/crates/plotnik-lib/src/diagnostics/mod.rs b/crates/plotnik-lib/src/diagnostics/mod.rs index d170ea73..7edb207a 100644 --- a/crates/plotnik-lib/src/diagnostics/mod.rs +++ b/crates/plotnik-lib/src/diagnostics/mod.rs @@ -85,7 +85,7 @@ impl Diagnostics { /// 1. Containment: when error A's suppression_range contains error B's display range, /// and A has higher priority, suppress B (only for structural errors) /// 2. Same position: when spans start at the same position, root-cause errors suppress structural ones - /// 3. Consequence errors (UnnamedDefNotLast) suppressed when any other error exists + /// 3. Consequence errors (UnnamedDef) suppressed when any other error exists /// 4. Adjacent: when error A ends exactly where error B starts, A suppresses B pub(crate) fn filtered(&self) -> Vec { if self.messages.is_empty() { diff --git a/crates/plotnik-lib/src/diagnostics/tests.rs b/crates/plotnik-lib/src/diagnostics/tests.rs index 92f30d7b..479e0c0a 100644 --- a/crates/plotnik-lib/src/diagnostics/tests.rs +++ b/crates/plotnik-lib/src/diagnostics/tests.rs @@ -271,7 +271,7 @@ fn diagnostic_kind_default_severity() { Severity::Error ); assert_eq!( - DiagnosticKind::UnnamedDefNotLast.default_severity(), + DiagnosticKind::UnnamedDef.default_severity(), Severity::Error ); } @@ -279,15 +279,15 @@ fn diagnostic_kind_default_severity() { #[test] fn diagnostic_kind_suppression_order() { // Higher priority (earlier in enum) suppresses lower priority (later in enum) - assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnnamedDefNotLast)); + assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnnamedDef)); assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UndefinedReference)); - assert!(DiagnosticKind::ExpectedExpression.suppresses(&DiagnosticKind::UnnamedDefNotLast)); + assert!(DiagnosticKind::ExpectedExpression.suppresses(&DiagnosticKind::UnnamedDef)); // Same kind doesn't suppress itself assert!(!DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnclosedTree)); // Lower priority doesn't suppress higher priority - assert!(!DiagnosticKind::UnnamedDefNotLast.suppresses(&DiagnosticKind::UnclosedTree)); + assert!(!DiagnosticKind::UnnamedDef.suppresses(&DiagnosticKind::UnclosedTree)); } #[test] @@ -364,7 +364,7 @@ fn filtered_no_suppression_disjoint_spans() { #[test] fn filtered_suppresses_lower_priority_contained() { let mut diagnostics = Diagnostics::new(); - // Higher priority error (UnclosedTree) contains lower priority (UnnamedDefNotLast) + // Higher priority error (UnclosedTree) contains lower priority (UnnamedDef) diagnostics .report( DiagnosticKind::UnclosedTree, @@ -373,7 +373,7 @@ fn filtered_suppresses_lower_priority_contained() { .emit(); diagnostics .report( - DiagnosticKind::UnnamedDefNotLast, + DiagnosticKind::UnnamedDef, TextRange::new(5.into(), 15.into()), ) .emit(); @@ -386,10 +386,10 @@ fn filtered_suppresses_lower_priority_contained() { #[test] fn filtered_consequence_suppressed_by_structural() { let mut diagnostics = Diagnostics::new(); - // Consequence error (UnnamedDefNotLast) suppressed when structural error (UnclosedTree) exists + // Consequence error (UnnamedDef) suppressed when structural error (UnclosedTree) exists diagnostics .report( - DiagnosticKind::UnnamedDefNotLast, + DiagnosticKind::UnnamedDef, TextRange::new(0.into(), 20.into()), ) .emit(); @@ -418,7 +418,7 @@ fn filtered_same_span_higher_priority_wins() { .emit(); diagnostics .report( - DiagnosticKind::UnnamedDefNotLast, + DiagnosticKind::UnnamedDef, TextRange::new(0.into(), 10.into()), ) .emit(); @@ -448,7 +448,7 @@ fn render_filtered() { .emit(); diagnostics .report( - DiagnosticKind::UnnamedDefNotLast, + DiagnosticKind::UnnamedDef, TextRange::new(5.into(), 15.into()), ) .message("unnamed def") diff --git a/crates/plotnik-lib/src/parser/ast_tests.rs b/crates/plotnik-lib/src/parser/ast_tests.rs index eb18a1f6..71f2044a 100644 --- a/crates/plotnik-lib/src/parser/ast_tests.rs +++ b/crates/plotnik-lib/src/parser/ast_tests.rs @@ -3,11 +3,11 @@ use indoc::indoc; #[test] fn simple_tree() { - let query = Query::try_from("(identifier)").unwrap(); + let query = Query::try_from("Q = (identifier)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode identifier "); } @@ -15,14 +15,14 @@ fn simple_tree() { #[test] fn nested_tree() { let input = indoc! {r#" - (function_definition name: (identifier)) + Q = (function_definition name: (identifier)) "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode function_definition FieldExpr name: NamedNode identifier @@ -31,33 +31,33 @@ fn nested_tree() { #[test] fn wildcard() { - let query = Query::try_from("(_)").unwrap(); + let query = Query::try_from("Q = (_)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode (any) "); } #[test] fn literal() { - let query = Query::try_from(r#""if""#).unwrap(); + let query = Query::try_from(r#"Q = "if""#).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r#" Root - Def + Def Q AnonymousNode "if" "#); } #[test] fn capture() { - let query = Query::try_from("(identifier) @name").unwrap(); + let query = Query::try_from("Q = (identifier) @name").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @name NamedNode identifier "); @@ -65,11 +65,11 @@ fn capture() { #[test] fn capture_with_type() { - let query = Query::try_from("(identifier) @name :: string").unwrap(); + let query = Query::try_from("Q = (identifier) @name :: string").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @name :: string NamedNode identifier "); @@ -90,7 +90,7 @@ fn named_definition() { fn reference() { let input = indoc! {r#" Expr = (identifier) - (call (Expr)) + Q = (call (Expr)) "#}; let query = Query::try_from(input).unwrap(); @@ -99,7 +99,7 @@ fn reference() { Root Def Expr NamedNode identifier - Def + Def Q NamedNode call Ref Expr "); @@ -107,11 +107,11 @@ fn reference() { #[test] fn alternation_unlabeled() { - let query = Query::try_from("[(identifier) (number)]").unwrap(); + let query = Query::try_from("Q = [(identifier) (number)]").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Alt Branch NamedNode identifier @@ -123,14 +123,14 @@ fn alternation_unlabeled() { #[test] fn alternation_tagged() { let input = indoc! {r#" - [Ident: (identifier) Num: (number)] + Q = [Ident: (identifier) Num: (number)] "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Alt Branch Ident: NamedNode identifier @@ -141,11 +141,11 @@ fn alternation_tagged() { #[test] fn sequence() { - let query = Query::try_from("{(a) (b) (c)}").unwrap(); + let query = Query::try_from("Q = {(a) (b) (c)}").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Seq NamedNode a NamedNode b @@ -155,11 +155,11 @@ fn sequence() { #[test] fn quantifier_star() { - let query = Query::try_from("(statement)*").unwrap(); + let query = Query::try_from("Q = (statement)*").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q QuantifiedExpr * NamedNode statement "); @@ -167,11 +167,11 @@ fn quantifier_star() { #[test] fn quantifier_plus() { - let query = Query::try_from("(statement)+").unwrap(); + let query = Query::try_from("Q = (statement)+").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q QuantifiedExpr + NamedNode statement "); @@ -179,11 +179,11 @@ fn quantifier_plus() { #[test] fn quantifier_optional() { - let query = Query::try_from("(statement)?").unwrap(); + let query = Query::try_from("Q = (statement)?").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q QuantifiedExpr ? NamedNode statement "); @@ -191,11 +191,11 @@ fn quantifier_optional() { #[test] fn quantifier_non_greedy() { - let query = Query::try_from("(statement)*?").unwrap(); + let query = Query::try_from("Q = (statement)*?").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q QuantifiedExpr *? NamedNode statement "); @@ -203,11 +203,11 @@ fn quantifier_non_greedy() { #[test] fn anchor() { - let query = Query::try_from("(block . (statement))").unwrap(); + let query = Query::try_from("Q = (block . (statement))").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode block . NamedNode statement @@ -216,11 +216,11 @@ fn anchor() { #[test] fn negated_field() { - let query = Query::try_from("(function !async)").unwrap(); + let query = Query::try_from("Q = (function !async)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode function NegatedField !async "); @@ -259,23 +259,23 @@ fn complex_example() { #[test] fn ast_with_errors() { - let query = Query::try_from("(call (Undefined))").unwrap(); + let query = Query::try_from("Q = (call (Undefined))").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `Undefined` is not defined | - 1 | (call (Undefined)) - | ^^^^^^^^^ + 1 | Q = (call (Undefined)) + | ^^^^^^^^^ "); } #[test] fn supertype() { - let query = Query::try_from("(expression/binary_expression)").unwrap(); + let query = Query::try_from("Q = (expression/binary_expression)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q NamedNode expression "); } @@ -283,7 +283,7 @@ fn supertype() { #[test] fn multiple_fields() { let input = indoc! {r#" - (binary_expression + Q = (binary_expression left: (_) @left operator: _ @op right: (_) @right) @expr @@ -293,7 +293,7 @@ fn multiple_fields() { assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @expr NamedNode binary_expression CapturedExpr @left diff --git a/crates/plotnik-lib/src/parser/grammar/items.rs b/crates/plotnik-lib/src/parser/grammar/items.rs index 3a767d56..412522d2 100644 --- a/crates/plotnik-lib/src/parser/grammar/items.rs +++ b/crates/plotnik-lib/src/parser/grammar/items.rs @@ -10,8 +10,6 @@ impl Parser<'_> { pub fn parse_root(&mut self) { self.start_node(SyntaxKind::Root); - let mut unnamed_def_spans: Vec = Vec::new(); - while !self.should_stop() && !self.currently_is(SyntaxKind::Error) { // LL(2): Id followed by Equals → named definition (if PascalCase) if self.currently_is(SyntaxKind::Id) && self.next_is(SyntaxKind::Equals) { @@ -28,15 +26,10 @@ impl Parser<'_> { self.finish_node(); if success { let end = self.last_non_trivia_end().unwrap_or(start); - unnamed_def_spans.push(TextRange::new(start, end)); - } - } - - if unnamed_def_spans.len() > 1 { - for span in &unnamed_def_spans[..unnamed_def_spans.len() - 1] { - let def_text = &self.source[usize::from(span.start())..usize::from(span.end())]; + let span = TextRange::new(start, end); + let def_text = &self.source[usize::from(start)..usize::from(end)]; self.diagnostics - .report(DiagnosticKind::UnnamedDefNotLast, *span) + .report(DiagnosticKind::UnnamedDef, span) .message(format!("give it a name like `Name = {}`", def_text.trim())) .emit(); } diff --git a/crates/plotnik-lib/src/parser/tests/grammar/alternations_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/alternations_tests.rs index 325108d4..f35f1f6c 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/alternations_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/alternations_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn alternation() { let input = indoc! {r#" - [(identifier) (string)] + Q = [(identifier) (string)] "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn alternation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -31,7 +33,7 @@ fn alternation() { #[test] fn alternation_with_anonymous() { let input = indoc! {r#" - ["true" "false"] + Q = ["true" "false"] "#}; let query = Query::try_from(input).unwrap(); @@ -39,6 +41,8 @@ fn alternation_with_anonymous() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -58,7 +62,7 @@ fn alternation_with_anonymous() { #[test] fn alternation_with_capture() { let input = indoc! {r#" - [(identifier) (string)] @value + Q = [(identifier) (string)] @value "#}; let query = Query::try_from(input).unwrap(); @@ -66,6 +70,8 @@ fn alternation_with_capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Alt BracketOpen "[" @@ -88,7 +94,7 @@ fn alternation_with_capture() { #[test] fn alternation_with_quantifier() { let input = indoc! {r#" - [ + Q = [ (identifier) (string)* @strings ] @@ -99,6 +105,8 @@ fn alternation_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -123,8 +131,9 @@ fn alternation_with_quantifier() { #[test] fn alternation_nested() { let input = indoc! {r#" - (expr - [(binary) (unary)]) + Q = (expr + [(binary) (unary)] + ) "#}; let query = Query::try_from(input).unwrap(); @@ -132,6 +141,8 @@ fn alternation_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "expr" @@ -155,8 +166,9 @@ fn alternation_nested() { #[test] fn alternation_in_field() { let input = indoc! {r#" - (call - arguments: [(string) (number)]) + Q = (call + arguments: [(string) (number)] + ) "#}; let query = Query::try_from(input).unwrap(); @@ -164,6 +176,8 @@ fn alternation_in_field() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "call" @@ -190,7 +204,7 @@ fn alternation_in_field() { #[test] fn unlabeled_alternation_three_items() { let input = indoc! {r#" - [(identifier) (number) (string)] + Q = [(identifier) (number) (string)] "#}; let query = Query::try_from(input).unwrap(); @@ -198,6 +212,8 @@ fn unlabeled_alternation_three_items() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -222,7 +238,7 @@ fn unlabeled_alternation_three_items() { #[test] fn tagged_alternation_simple() { let input = indoc! {r#" - [ + Q = [ Ident: (identifier) Num: (number) ] @@ -233,6 +249,8 @@ fn tagged_alternation_simple() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -256,7 +274,7 @@ fn tagged_alternation_simple() { #[test] fn tagged_alternation_single_line() { let input = indoc! {r#" - [A: (a) B: (b) C: (c)] + Q = [A: (a) B: (b) C: (c)] "#}; let query = Query::try_from(input).unwrap(); @@ -264,6 +282,8 @@ fn tagged_alternation_single_line() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -294,7 +314,7 @@ fn tagged_alternation_single_line() { #[test] fn tagged_alternation_with_captures() { let input = indoc! {r#" - [ + Q = [ Assign: (assignment_expression left: (identifier) @left) Call: (call_expression function: (identifier) @func) ] @stmt @@ -305,6 +325,8 @@ fn tagged_alternation_with_captures() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Alt BracketOpen "[" @@ -351,7 +373,7 @@ fn tagged_alternation_with_captures() { #[test] fn tagged_alternation_with_type_annotation() { let input = indoc! {r#" - [ + Q = [ Base: (identifier) @name Access: (member_expression object: (_) @obj) ] @chain :: MemberChain @@ -362,6 +384,8 @@ fn tagged_alternation_with_type_annotation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Alt BracketOpen "[" @@ -404,7 +428,7 @@ fn tagged_alternation_with_type_annotation() { #[test] fn tagged_alternation_nested() { let input = indoc! {r#" - (expr + Q = (expr [ Binary: (binary_expression) Unary: (unary_expression) @@ -416,6 +440,8 @@ fn tagged_alternation_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "expr" @@ -487,7 +513,7 @@ fn tagged_alternation_in_named_def() { #[test] fn tagged_alternation_with_quantifier() { let input = indoc! {r#" - [ + Q = [ Single: (statement) Multiple: (statement)+ ] @@ -498,6 +524,8 @@ fn tagged_alternation_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -523,7 +551,7 @@ fn tagged_alternation_with_quantifier() { #[test] fn tagged_alternation_with_sequence() { let input = indoc! {r#" - [ + Q = [ Pair: {(key) (value)} Single: (value) ] @@ -534,6 +562,8 @@ fn tagged_alternation_with_sequence() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -564,7 +594,7 @@ fn tagged_alternation_with_sequence() { #[test] fn tagged_alternation_with_nested_alternation() { let input = indoc! {r#" - [ + Q = [ Literal: [(number) (string)] Ident: (identifier) ] @@ -575,6 +605,8 @@ fn tagged_alternation_with_nested_alternation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch diff --git a/crates/plotnik-lib/src/parser/tests/grammar/anchors_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/anchors_tests.rs index 4f314ebf..0be13661 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/anchors_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/anchors_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn anchor_first_child() { let input = indoc! {r#" - (block . (first_statement)) + Q = (block . (first_statement)) "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn anchor_first_child() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "block" @@ -28,7 +30,7 @@ fn anchor_first_child() { #[test] fn anchor_last_child() { let input = indoc! {r#" - (block (last_statement) .) + Q = (block (last_statement) .) "#}; let query = Query::try_from(input).unwrap(); @@ -36,6 +38,8 @@ fn anchor_last_child() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "block" @@ -52,7 +56,7 @@ fn anchor_last_child() { #[test] fn anchor_adjacency() { let input = indoc! {r#" - (dotted_name (identifier) @a . (identifier) @b) + Q = (dotted_name (identifier) @a . (identifier) @b) "#}; let query = Query::try_from(input).unwrap(); @@ -60,6 +64,8 @@ fn anchor_adjacency() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "dotted_name" @@ -86,7 +92,7 @@ fn anchor_adjacency() { #[test] fn anchor_both_ends() { let input = indoc! {r#" - (array . (element) .) + Q = (array . (element) .) "#}; let query = Query::try_from(input).unwrap(); @@ -94,6 +100,8 @@ fn anchor_both_ends() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "array" @@ -112,7 +120,7 @@ fn anchor_both_ends() { #[test] fn anchor_multiple_adjacent() { let input = indoc! {r#" - (tuple . (a) . (b) . (c) .) + Q = (tuple . (a) . (b) . (c) .) "#}; let query = Query::try_from(input).unwrap(); @@ -120,6 +128,8 @@ fn anchor_multiple_adjacent() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "tuple" @@ -150,7 +160,7 @@ fn anchor_multiple_adjacent() { #[test] fn anchor_in_sequence() { let input = indoc! {r#" - {. (first) (second) .} + Q = {. (first) (second) .} "#}; let query = Query::try_from(input).unwrap(); @@ -158,6 +168,8 @@ fn anchor_in_sequence() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Anchor diff --git a/crates/plotnik-lib/src/parser/tests/grammar/captures_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/captures_tests.rs index fb0f8410..03f897a9 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/captures_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/captures_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn capture() { let input = indoc! {r#" - (identifier) @name + Q = (identifier) @name "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -25,7 +27,7 @@ fn capture() { #[test] fn capture_nested() { let input = indoc! {r#" - (call function: (identifier) @func) + Q = (call function: (identifier) @func) "#}; let query = Query::try_from(input).unwrap(); @@ -33,6 +35,8 @@ fn capture_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "call" @@ -53,7 +57,7 @@ fn capture_nested() { #[test] fn multiple_captures() { let input = indoc! {r#" - (binary + Q = (binary left: (_) @left right: (_) @right) @expr "#}; @@ -63,6 +67,8 @@ fn multiple_captures() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -96,7 +102,7 @@ fn multiple_captures() { #[test] fn capture_with_type_annotation() { let input = indoc! {r#" - (identifier) @name :: string + Q = (identifier) @name :: string "#}; let query = Query::try_from(input).unwrap(); @@ -104,6 +110,8 @@ fn capture_with_type_annotation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -120,7 +128,7 @@ fn capture_with_type_annotation() { #[test] fn capture_with_custom_type() { let input = indoc! {r#" - (function_declaration) @fn :: FunctionDecl + Q = (function_declaration) @fn :: FunctionDecl "#}; let query = Query::try_from(input).unwrap(); @@ -128,6 +136,8 @@ fn capture_with_custom_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -144,7 +154,7 @@ fn capture_with_custom_type() { #[test] fn capture_without_type_annotation() { let input = indoc! {r#" - (identifier) @name + Q = (identifier) @name "#}; let query = Query::try_from(input).unwrap(); @@ -152,6 +162,8 @@ fn capture_without_type_annotation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -165,7 +177,7 @@ fn capture_without_type_annotation() { #[test] fn multiple_captures_with_types() { let input = indoc! {r#" - (binary + Q = (binary left: (_) @left :: Node right: (_) @right :: string) @expr :: BinaryExpr "#}; @@ -175,6 +187,8 @@ fn multiple_captures_with_types() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -217,7 +231,7 @@ fn multiple_captures_with_types() { #[test] fn sequence_capture_with_type() { let input = indoc! {r#" - {(a) (b)} @seq :: MySequence + Q = {(a) (b)} @seq :: MySequence "#}; let query = Query::try_from(input).unwrap(); @@ -225,6 +239,8 @@ fn sequence_capture_with_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Seq BraceOpen "{" @@ -248,7 +264,7 @@ fn sequence_capture_with_type() { #[test] fn alternation_capture_with_type() { let input = indoc! {r#" - [(identifier) (number)] @value :: Value + Q = [(identifier) (number)] @value :: Value "#}; let query = Query::try_from(input).unwrap(); @@ -256,6 +272,8 @@ fn alternation_capture_with_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Alt BracketOpen "[" @@ -281,7 +299,7 @@ fn alternation_capture_with_type() { #[test] fn quantified_capture_with_type() { let input = indoc! {r#" - (statement)+ @stmts :: Statement + Q = (statement)+ @stmts :: Statement "#}; let query = Query::try_from(input).unwrap(); @@ -289,6 +307,8 @@ fn quantified_capture_with_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Quantifier Tree @@ -307,7 +327,7 @@ fn quantified_capture_with_type() { #[test] fn nested_captures_with_types() { let input = indoc! {r#" - (function + Q = (function name: (identifier) @name :: string body: (block (statement)* @body_stmts :: Statement)) @func :: Function @@ -318,6 +338,8 @@ fn nested_captures_with_types() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -366,7 +388,7 @@ fn nested_captures_with_types() { #[test] fn capture_with_type_no_spaces() { let input = indoc! {r#" - (identifier) @name::string + Q = (identifier) @name::string "#}; let query = Query::try_from(input).unwrap(); @@ -374,6 +396,8 @@ fn capture_with_type_no_spaces() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -390,7 +414,7 @@ fn capture_with_type_no_spaces() { #[test] fn capture_literal() { let input = indoc! {r#" - "foo" @keyword + Q = "foo" @keyword "#}; let query = Query::try_from(input).unwrap(); @@ -398,6 +422,8 @@ fn capture_literal() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Str DoubleQuote "\"" @@ -411,7 +437,7 @@ fn capture_literal() { #[test] fn capture_literal_with_type() { let input = indoc! {r#" - "return" @kw :: string + Q = "return" @kw :: string "#}; let query = Query::try_from(input).unwrap(); @@ -419,6 +445,8 @@ fn capture_literal_with_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Str DoubleQuote "\"" @@ -435,7 +463,7 @@ fn capture_literal_with_type() { #[test] fn capture_literal_in_tree() { let input = indoc! {r#" - (binary_expression "+" @op) + Q = (binary_expression "+" @op) "#}; let query = Query::try_from(input).unwrap(); @@ -443,6 +471,8 @@ fn capture_literal_in_tree() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "binary_expression" @@ -460,7 +490,7 @@ fn capture_literal_in_tree() { #[test] fn capture_literal_with_quantifier() { let input = indoc! {r#" - ","* @commas + Q = ","* @commas "#}; let query = Query::try_from(input).unwrap(); @@ -468,6 +498,8 @@ fn capture_literal_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Quantifier Str diff --git a/crates/plotnik-lib/src/parser/tests/grammar/definitions_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/definitions_tests.rs index e61e763a..e53d6647 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/definitions_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/definitions_tests.rs @@ -169,7 +169,7 @@ fn named_def_then_expression() { "#}; let query = Query::try_from(input).unwrap(); - assert!(query.is_valid()); + assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_cst(), @r#" Root Def @@ -371,7 +371,7 @@ fn named_def_with_type_annotation() { fn unnamed_def_allowed_as_last() { let input = indoc! {r#" Expr = (identifier) - (program (Expr) @value) + Q = (program (Expr) @value) "#}; let query = Query::try_from(input).unwrap(); @@ -386,6 +386,8 @@ fn unnamed_def_allowed_as_last() { Id "identifier" ParenClose ")" Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "program" diff --git a/crates/plotnik-lib/src/parser/tests/grammar/fields_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/fields_tests.rs index b8a7c0fd..9e7d16c3 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/fields_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/fields_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn field_expression() { let input = indoc! {r#" - (call function: (identifier)) + Q = (call function: (identifier)) "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn field_expression() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "call" @@ -29,7 +31,7 @@ fn field_expression() { #[test] fn multiple_fields() { let input = indoc! {r#" - (assignment + Q = (assignment left: (identifier) right: (expression)) "#}; @@ -39,6 +41,8 @@ fn multiple_fields() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "assignment" @@ -63,7 +67,7 @@ fn multiple_fields() { #[test] fn negated_field() { let input = indoc! {r#" - (function !async) + Q = (function !async) "#}; let query = Query::try_from(input).unwrap(); @@ -71,6 +75,8 @@ fn negated_field() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "function" @@ -84,7 +90,7 @@ fn negated_field() { #[test] fn negated_and_regular_fields() { let input = indoc! {r#" - (function + Q = (function !async name: (identifier)) "#}; @@ -94,6 +100,8 @@ fn negated_and_regular_fields() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "function" @@ -114,7 +122,7 @@ fn negated_and_regular_fields() { #[test] fn mixed_children_and_fields() { let input = indoc! {r#" - (if + Q = (if condition: (expr) (then_block) else: (else_block)) @@ -125,6 +133,8 @@ fn mixed_children_and_fields() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "if" @@ -153,7 +163,7 @@ fn mixed_children_and_fields() { #[test] fn fields_and_quantifiers() { let input = indoc! {r#" - (node + Q = (node foo: (foo)? foo: (foo)?? bar: (bar)* @@ -167,6 +177,8 @@ fn fields_and_quantifiers() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "node" @@ -231,7 +243,7 @@ fn fields_and_quantifiers() { #[test] fn fields_with_quantifiers_and_captures() { let input = indoc! {r#" - (node foo: (bar)* @baz) + Q = (node foo: (bar)* @baz) "#}; let query = Query::try_from(input).unwrap(); @@ -239,6 +251,8 @@ fn fields_with_quantifiers_and_captures() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "node" diff --git a/crates/plotnik-lib/src/parser/tests/grammar/nodes_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/nodes_tests.rs index c9986ba1..82499f97 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/nodes_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/nodes_tests.rs @@ -11,7 +11,7 @@ fn empty_input() { #[test] fn simple_named_node() { let input = indoc! {r#" - (identifier) + Q = (identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -19,6 +19,8 @@ fn simple_named_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "identifier" @@ -29,7 +31,7 @@ fn simple_named_node() { #[test] fn nested_node() { let input = indoc! {r#" - (function_definition name: (identifier)) + Q = (function_definition name: (identifier)) "#}; let query = Query::try_from(input).unwrap(); @@ -37,6 +39,8 @@ fn nested_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "function_definition" @@ -54,7 +58,7 @@ fn nested_node() { #[test] fn deeply_nested() { let input = indoc! {r#" - (a + Q = (a (b (c (d)))) @@ -65,6 +69,8 @@ fn deeply_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "a" @@ -87,7 +93,7 @@ fn deeply_nested() { #[test] fn sibling_children() { let input = indoc! {r#" - (block + Q = (block (statement) (statement) (statement)) @@ -98,6 +104,8 @@ fn sibling_children() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "block" @@ -120,7 +128,7 @@ fn sibling_children() { #[test] fn wildcard() { let input = indoc! {r#" - (_) + Q = (_) "#}; let query = Query::try_from(input).unwrap(); @@ -128,6 +136,8 @@ fn wildcard() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Underscore "_" @@ -138,7 +148,7 @@ fn wildcard() { #[test] fn anonymous_node() { let input = indoc! {r#" - "if" + Q = "if" "#}; let query = Query::try_from(input).unwrap(); @@ -146,6 +156,8 @@ fn anonymous_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Str DoubleQuote "\"" StrVal "if" @@ -156,7 +168,7 @@ fn anonymous_node() { #[test] fn anonymous_node_operator() { let input = indoc! {r#" - "+=" + Q = "+=" "#}; let query = Query::try_from(input).unwrap(); @@ -164,6 +176,8 @@ fn anonymous_node_operator() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Str DoubleQuote "\"" StrVal "+=" @@ -174,7 +188,7 @@ fn anonymous_node_operator() { #[test] fn supertype_basic() { let input = indoc! {r#" - (expression/binary_expression) + Q = (expression/binary_expression) "#}; let query = Query::try_from(input).unwrap(); @@ -182,6 +196,8 @@ fn supertype_basic() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "expression" @@ -194,7 +210,7 @@ fn supertype_basic() { #[test] fn supertype_with_string_subtype() { let input = indoc! {r#" - (expression/"()") + Q = (expression/"()") "#}; let query = Query::try_from(input).unwrap(); @@ -202,6 +218,8 @@ fn supertype_with_string_subtype() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "expression" @@ -216,7 +234,7 @@ fn supertype_with_string_subtype() { #[test] fn supertype_with_capture() { let input = indoc! {r#" - (expression/binary_expression) @expr + Q = (expression/binary_expression) @expr "#}; let query = Query::try_from(input).unwrap(); @@ -224,6 +242,8 @@ fn supertype_with_capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -239,7 +259,7 @@ fn supertype_with_capture() { #[test] fn supertype_with_children() { let input = indoc! {r#" - (expression/binary_expression + Q = (expression/binary_expression left: (_) @left right: (_) @right) "#}; @@ -249,6 +269,8 @@ fn supertype_with_children() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "expression" @@ -281,7 +303,7 @@ fn supertype_with_children() { #[test] fn supertype_nested() { let input = indoc! {r#" - (statement/expression_statement + Q = (statement/expression_statement (expression/call_expression)) "#}; @@ -290,6 +312,8 @@ fn supertype_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "statement" @@ -308,7 +332,7 @@ fn supertype_nested() { #[test] fn supertype_in_alternation() { let input = indoc! {r#" - [(expression/identifier) (expression/number)] + Q = [(expression/identifier) (expression/number)] "#}; let query = Query::try_from(input).unwrap(); @@ -316,6 +340,8 @@ fn supertype_in_alternation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -339,7 +365,7 @@ fn supertype_in_alternation() { #[test] fn no_supertype_plain_node() { let input = indoc! {r#" - (identifier) + Q = (identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -347,6 +373,8 @@ fn no_supertype_plain_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "identifier" diff --git a/crates/plotnik-lib/src/parser/tests/grammar/quantifiers_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/quantifiers_tests.rs index 0e52d2ab..1aa082c7 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/quantifiers_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/quantifiers_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn quantifier_star() { let input = indoc! {r#" - (statement)* + Q = (statement)* "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn quantifier_star() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Tree ParenOpen "(" @@ -24,7 +26,7 @@ fn quantifier_star() { #[test] fn quantifier_plus() { let input = indoc! {r#" - (statement)+ + Q = (statement)+ "#}; let query = Query::try_from(input).unwrap(); @@ -32,6 +34,8 @@ fn quantifier_plus() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Tree ParenOpen "(" @@ -44,7 +48,7 @@ fn quantifier_plus() { #[test] fn quantifier_optional() { let input = indoc! {r#" - (statement)? + Q = (statement)? "#}; let query = Query::try_from(input).unwrap(); @@ -52,6 +56,8 @@ fn quantifier_optional() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Tree ParenOpen "(" @@ -64,7 +70,7 @@ fn quantifier_optional() { #[test] fn quantifier_with_capture() { let input = indoc! {r#" - (statement)* @statements + Q = (statement)* @statements "#}; let query = Query::try_from(input).unwrap(); @@ -72,6 +78,8 @@ fn quantifier_with_capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Quantifier Tree @@ -87,7 +95,7 @@ fn quantifier_with_capture() { #[test] fn quantifier_inside_node() { let input = indoc! {r#" - (block + Q = (block (statement)*) "#}; @@ -96,6 +104,8 @@ fn quantifier_inside_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "block" diff --git a/crates/plotnik-lib/src/parser/tests/grammar/sequences_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/sequences_tests.rs index eea5749f..de18f9ae 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/sequences_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/sequences_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn simple_sequence() { let input = indoc! {r#" - {(a) (b)} + Q = {(a) (b)} "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn simple_sequence() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Tree @@ -29,7 +31,7 @@ fn simple_sequence() { #[test] fn empty_sequence() { let input = indoc! {r#" - {} + Q = {} "#}; let query = Query::try_from(input).unwrap(); @@ -37,6 +39,8 @@ fn empty_sequence() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" BraceClose "}" @@ -46,7 +50,7 @@ fn empty_sequence() { #[test] fn sequence_single_element() { let input = indoc! {r#" - {(identifier)} + Q = {(identifier)} "#}; let query = Query::try_from(input).unwrap(); @@ -54,6 +58,8 @@ fn sequence_single_element() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Tree @@ -67,7 +73,7 @@ fn sequence_single_element() { #[test] fn sequence_with_captures() { let input = indoc! {r#" - {(comment)* @comments (function) @fn} + Q = {(comment)* @comments (function) @fn} "#}; let query = Query::try_from(input).unwrap(); @@ -75,6 +81,8 @@ fn sequence_with_captures() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Capture @@ -100,7 +108,7 @@ fn sequence_with_captures() { #[test] fn sequence_with_quantifier() { let input = indoc! {r#" - {(a) (b)}+ + Q = {(a) (b)}+ "#}; let query = Query::try_from(input).unwrap(); @@ -108,6 +116,8 @@ fn sequence_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Seq BraceOpen "{" @@ -127,7 +137,7 @@ fn sequence_with_quantifier() { #[test] fn nested_sequences() { let input = indoc! {r#" - {{(a)} {(b)}} + Q = {{(a)} {(b)}} "#}; let query = Query::try_from(input).unwrap(); @@ -135,6 +145,8 @@ fn nested_sequences() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Seq @@ -158,7 +170,7 @@ fn nested_sequences() { #[test] fn sequence_in_named_node() { let input = indoc! {r#" - (block {(statement) (statement)}) + Q = (block {(statement) (statement)}) "#}; let query = Query::try_from(input).unwrap(); @@ -166,6 +178,8 @@ fn sequence_in_named_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "block" @@ -187,7 +201,7 @@ fn sequence_in_named_node() { #[test] fn sequence_with_alternation() { let input = indoc! {r#" - {[(a) (b)] (c)} + Q = {[(a) (b)] (c)} "#}; let query = Query::try_from(input).unwrap(); @@ -195,6 +209,8 @@ fn sequence_with_alternation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Alt @@ -221,7 +237,7 @@ fn sequence_with_alternation() { #[test] fn sequence_comma_separated_expression() { let input = indoc! {r#" - {(number) {"," (number)}*} + Q = {(number) {"," (number)}*} "#}; let query = Query::try_from(input).unwrap(); @@ -229,6 +245,8 @@ fn sequence_comma_separated_expression() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Tree @@ -255,7 +273,7 @@ fn sequence_comma_separated_expression() { #[test] fn sequence_with_anchor() { let input = indoc! {r#" - {. (first) (second) .} + Q = {. (first) (second) .} "#}; let query = Query::try_from(input).unwrap(); @@ -263,6 +281,8 @@ fn sequence_with_anchor() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Anchor diff --git a/crates/plotnik-lib/src/parser/tests/grammar/special_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/special_tests.rs index 7afa7c2b..543df22a 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/special_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/special_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn error_node() { let input = indoc! {r#" - (ERROR) + Q = (ERROR) "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,8 @@ fn error_node() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" KwError "ERROR" @@ -22,7 +24,7 @@ fn error_node() { #[test] fn error_node_with_capture() { let input = indoc! {r#" - (ERROR) @err + Q = (ERROR) @err "#}; let query = Query::try_from(input).unwrap(); @@ -30,6 +32,8 @@ fn error_node_with_capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -43,7 +47,7 @@ fn error_node_with_capture() { #[test] fn missing_node_bare() { let input = indoc! {r#" - (MISSING) + Q = (MISSING) "#}; let query = Query::try_from(input).unwrap(); @@ -51,6 +55,8 @@ fn missing_node_bare() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" KwMissing "MISSING" @@ -61,7 +67,7 @@ fn missing_node_bare() { #[test] fn missing_node_with_type() { let input = indoc! {r#" - (MISSING identifier) + Q = (MISSING identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -69,6 +75,8 @@ fn missing_node_with_type() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" KwMissing "MISSING" @@ -80,7 +88,7 @@ fn missing_node_with_type() { #[test] fn missing_node_with_string() { let input = indoc! {r#" - (MISSING ";") + Q = (MISSING ";") "#}; let query = Query::try_from(input).unwrap(); @@ -88,6 +96,8 @@ fn missing_node_with_string() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" KwMissing "MISSING" @@ -101,7 +111,7 @@ fn missing_node_with_string() { #[test] fn missing_node_with_capture() { let input = indoc! {r#" - (MISSING ";") @missing_semi + Q = (MISSING ";") @missing_semi "#}; let query = Query::try_from(input).unwrap(); @@ -109,6 +119,8 @@ fn missing_node_with_capture() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Capture Tree ParenOpen "(" @@ -125,7 +137,7 @@ fn missing_node_with_capture() { #[test] fn error_in_alternation() { let input = indoc! {r#" - [(ERROR) (identifier)] + Q = [(ERROR) (identifier)] "#}; let query = Query::try_from(input).unwrap(); @@ -133,6 +145,8 @@ fn error_in_alternation() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -152,7 +166,7 @@ fn error_in_alternation() { #[test] fn missing_in_sequence() { let input = indoc! {r#" - {(MISSING ";") (identifier)} + Q = {(MISSING ";") (identifier)} "#}; let query = Query::try_from(input).unwrap(); @@ -160,6 +174,8 @@ fn missing_in_sequence() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Seq BraceOpen "{" Tree @@ -180,7 +196,7 @@ fn missing_in_sequence() { #[test] fn special_node_nested() { let input = indoc! {r#" - (function_definition + Q = (function_definition body: (block (ERROR))) "#}; @@ -189,6 +205,8 @@ fn special_node_nested() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "function_definition" @@ -210,7 +228,7 @@ fn special_node_nested() { #[test] fn error_with_quantifier() { let input = indoc! {r#" - (ERROR)* + Q = (ERROR)* "#}; let query = Query::try_from(input).unwrap(); @@ -218,6 +236,8 @@ fn error_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Tree ParenOpen "(" @@ -230,7 +250,7 @@ fn error_with_quantifier() { #[test] fn missing_with_quantifier() { let input = indoc! {r#" - (MISSING identifier)? + Q = (MISSING identifier)? "#}; let query = Query::try_from(input).unwrap(); @@ -238,6 +258,8 @@ fn missing_with_quantifier() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Quantifier Tree ParenOpen "(" diff --git a/crates/plotnik-lib/src/parser/tests/grammar/trivia_tests.rs b/crates/plotnik-lib/src/parser/tests/grammar/trivia_tests.rs index d5916971..791a0075 100644 --- a/crates/plotnik-lib/src/parser/tests/grammar/trivia_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/grammar/trivia_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn whitespace_preserved() { let input = indoc! {r#" - (identifier) @name + Q = (identifier) @name "#}; let query = Query::try_from(input).unwrap(); @@ -12,6 +12,10 @@ fn whitespace_preserved() { insta::assert_snapshot!(query.dump_cst_full(), @r#" Root Def + Id "Q" + Whitespace " " + Equals "=" + Whitespace " " Capture Tree ParenOpen "(" @@ -28,7 +32,7 @@ fn whitespace_preserved() { fn comment_preserved() { let input = indoc! {r#" // comment - (identifier) + Q = (identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -38,6 +42,10 @@ fn comment_preserved() { LineComment "// comment" Newline "\n" Def + Id "Q" + Whitespace " " + Equals "=" + Whitespace " " Tree ParenOpen "(" Id "identifier" @@ -49,7 +57,7 @@ fn comment_preserved() { #[test] fn comment_inside_expression() { let input = indoc! {r#" - (call // inline + Q = (call // inline name: (identifier)) "#}; @@ -58,6 +66,10 @@ fn comment_inside_expression() { insta::assert_snapshot!(query.dump_cst_full(), @r#" Root Def + Id "Q" + Whitespace " " + Equals "=" + Whitespace " " Tree ParenOpen "(" Id "call" @@ -82,7 +94,7 @@ fn comment_inside_expression() { fn trivia_filtered_by_default() { let input = indoc! {r#" // comment - (identifier) + Q = (identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -90,6 +102,8 @@ fn trivia_filtered_by_default() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "identifier" @@ -100,7 +114,7 @@ fn trivia_filtered_by_default() { #[test] fn trivia_between_alternation_items() { let input = indoc! {r#" - [ + Q = [ (a) (b) ] @@ -111,6 +125,10 @@ fn trivia_between_alternation_items() { insta::assert_snapshot!(query.dump_cst_full(), @r#" Root Def + Id "Q" + Whitespace " " + Equals "=" + Whitespace " " Alt BracketOpen "[" Newline "\n" diff --git a/crates/plotnik-lib/src/parser/tests/recovery/coverage_tests.rs b/crates/plotnik-lib/src/parser/tests/recovery/coverage_tests.rs index a3a50a05..a783fac6 100644 --- a/crates/plotnik-lib/src/parser/tests/recovery/coverage_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/recovery/coverage_tests.rs @@ -132,7 +132,7 @@ fn many_fields_exhaust_exec_fuel() { #[test] fn named_def_missing_equals_with_garbage() { let input = indoc! {r#" - Expr ^^^ (identifier) + Q = Expr ^^^ (identifier) "#}; let query = Query::try_from(input).unwrap(); @@ -140,13 +140,13 @@ fn named_def_missing_equals_with_garbage() { insta::assert_snapshot!(query.dump_diagnostics(), @r#" error: bare identifier is not a valid expression; wrap in parentheses: `(identifier)` | - 1 | Expr ^^^ (identifier) - | ^^^^ + 1 | Q = Expr ^^^ (identifier) + | ^^^^ error: unexpected token; try `(node)`, `[a b]`, `{a b}`, `"literal"`, or `_` | - 1 | Expr ^^^ (identifier) - | ^^^ + 1 | Q = Expr ^^^ (identifier) + | ^^^ "#); } @@ -175,7 +175,7 @@ fn named_def_missing_equals_recovers_to_next_def() { #[test] fn empty_double_quote_string() { let input = indoc! {r#" - (a "") + Q = (a "") "#}; let query = Query::try_from(input).unwrap(); @@ -183,6 +183,8 @@ fn empty_double_quote_string() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "a" @@ -196,7 +198,7 @@ fn empty_double_quote_string() { #[test] fn empty_single_quote_string() { let input = indoc! {r#" - (a '') + Q = (a '') "#}; let query = Query::try_from(input).unwrap(); @@ -204,6 +206,8 @@ fn empty_single_quote_string() { insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "a" @@ -216,13 +220,15 @@ fn empty_single_quote_string() { #[test] fn single_quote_string_is_valid() { - let input = "(node 'if')"; + let input = "Q = (node 'if')"; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "node" @@ -236,13 +242,15 @@ fn single_quote_string_is_valid() { #[test] fn single_quote_in_alternation() { - let input = "['public' 'private']"; + let input = "Q = ['public' 'private']"; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Alt BracketOpen "[" Branch @@ -261,13 +269,15 @@ fn single_quote_in_alternation() { #[test] fn single_quote_with_escape() { - let input = r"(node 'it\'s')"; + let input = r"Q = (node 'it\'s')"; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" Id "node" @@ -281,13 +291,15 @@ fn single_quote_with_escape() { #[test] fn missing_with_nested_tree_parses() { - let input = "(MISSING (something))"; + let input = "Q = (MISSING (something))"; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_cst(), @r#" Root Def + Id "Q" + Equals "=" Tree ParenOpen "(" KwMissing "MISSING" diff --git a/crates/plotnik-lib/src/parser/tests/recovery/validation_tests.rs b/crates/plotnik-lib/src/parser/tests/recovery/validation_tests.rs index 4356fc5b..6967e70b 100644 --- a/crates/plotnik-lib/src/parser/tests/recovery/validation_tests.rs +++ b/crates/plotnik-lib/src/parser/tests/recovery/validation_tests.rs @@ -212,10 +212,15 @@ fn unnamed_def_not_allowed_in_middle() { let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" - error: only the last definition can be unnamed — give it a name like `Name = (first)` + error: definitions must be named — give it a name like `Name = (first)` | 1 | (first) | ^^^^^^^ + + error: definitions must be named — give it a name like `Name = (last)` + | + 3 | (last) + | ^^^^^^ "); } @@ -230,15 +235,20 @@ fn multiple_unnamed_defs_errors_for_all_but_last() { let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" - error: only the last definition can be unnamed — give it a name like `Name = (first)` + error: definitions must be named — give it a name like `Name = (first)` | 1 | (first) | ^^^^^^^ - error: only the last definition can be unnamed — give it a name like `Name = (second)` + error: definitions must be named — give it a name like `Name = (second)` | 2 | (second) | ^^^^^^^^ + + error: definitions must be named — give it a name like `Name = (third)` + | + 3 | (third) + | ^^^^^^^ "); } @@ -251,15 +261,20 @@ fn capture_space_after_dot_is_anchor() { let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" - error: only the last definition can be unnamed — give it a name like `Name = (identifier) @foo` + error: definitions must be named — give it a name like `Name = (identifier) @foo` | 1 | (identifier) @foo . (other) | ^^^^^^^^^^^^^^^^^ - error: only the last definition can be unnamed — give it a name like `Name = .` + error: definitions must be named — give it a name like `Name = .` | 1 | (identifier) @foo . (other) | ^ + + error: definitions must be named — give it a name like `Name = (other)` + | + 1 | (identifier) @foo . (other) + | ^^^^^^^ "); } diff --git a/crates/plotnik-lib/src/query/alt_kinds_tests.rs b/crates/plotnik-lib/src/query/alt_kinds_tests.rs index 307806b5..02e2bc05 100644 --- a/crates/plotnik-lib/src/query/alt_kinds_tests.rs +++ b/crates/plotnik-lib/src/query/alt_kinds_tests.rs @@ -2,11 +2,11 @@ use crate::Query; #[test] fn tagged_alternation_valid() { - let query = Query::try_from("[A: (a) B: (b)]").unwrap(); + let query = Query::try_from("Q = [A: (a) B: (b)]").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Alt Branch A: NamedNode a @@ -17,11 +17,11 @@ fn tagged_alternation_valid() { #[test] fn untagged_alternation_valid() { - let query = Query::try_from("[(a) (b)]").unwrap(); + let query = Query::try_from("Q = [(a) (b)]").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Alt Branch NamedNode a @@ -32,15 +32,15 @@ fn untagged_alternation_valid() { #[test] fn mixed_alternation_tagged_first() { - let query = Query::try_from("[A: (a) (b)]").unwrap(); + let query = Query::try_from("Q = [A: (a) (b)]").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: cannot mix labeled and unlabeled branches | - 1 | [A: (a) (b)] - | - ^^^ - | | - | tagged branch here + 1 | Q = [A: (a) (b)] + | - ^^^ + | | + | tagged branch here "); } @@ -48,7 +48,7 @@ fn mixed_alternation_tagged_first() { fn mixed_alternation_untagged_first() { let query = Query::try_from( r#" - [ + Q = [ (a) B: (b) ] @@ -68,46 +68,46 @@ fn mixed_alternation_untagged_first() { #[test] fn nested_mixed_alternation() { - let query = Query::try_from("(call [A: (a) (b)])").unwrap(); + let query = Query::try_from("Q = (call [A: (a) (b)])").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: cannot mix labeled and unlabeled branches | - 1 | (call [A: (a) (b)]) - | - ^^^ - | | - | tagged branch here + 1 | Q = (call [A: (a) (b)]) + | - ^^^ + | | + | tagged branch here "); } #[test] fn multiple_mixed_alternations() { - let query = Query::try_from("(foo [A: (a) (b)] [C: (c) (d)])").unwrap(); + let query = Query::try_from("Q = (foo [A: (a) (b)] [C: (c) (d)])").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: cannot mix labeled and unlabeled branches | - 1 | (foo [A: (a) (b)] [C: (c) (d)]) - | - ^^^ - | | - | tagged branch here + 1 | Q = (foo [A: (a) (b)] [C: (c) (d)]) + | - ^^^ + | | + | tagged branch here error: cannot mix labeled and unlabeled branches | - 1 | (foo [A: (a) (b)] [C: (c) (d)]) - | - ^^^ - | | - | tagged branch here + 1 | Q = (foo [A: (a) (b)] [C: (c) (d)]) + | - ^^^ + | | + | tagged branch here "); } #[test] fn single_branch_no_error() { - let query = Query::try_from("[A: (a)]").unwrap(); + let query = Query::try_from("Q = [A: (a)]").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q Alt Branch A: NamedNode a diff --git a/crates/plotnik-lib/src/query/dependencies_tests.rs b/crates/plotnik-lib/src/query/dependencies_tests.rs index ad3f23bf..98a1c747 100644 --- a/crates/plotnik-lib/src/query/dependencies_tests.rs +++ b/crates/plotnik-lib/src/query/dependencies_tests.rs @@ -350,7 +350,7 @@ fn valid_non_recursive_reference() { fn valid_entry_point_using_recursive_def() { let input = indoc! {r#" E = [(x) (call (E))] - (program (E)) + Q = (program (E)) "#}; let query = Query::try_from(input).unwrap(); diff --git a/crates/plotnik-lib/src/query/expr_arity_tests.rs b/crates/plotnik-lib/src/query/expr_arity_tests.rs index 6859eba8..ce146b35 100644 --- a/crates/plotnik-lib/src/query/expr_arity_tests.rs +++ b/crates/plotnik-lib/src/query/expr_arity_tests.rs @@ -3,22 +3,22 @@ use indoc::indoc; #[test] fn tree_is_one() { - let query = Query::try_from("(identifier)").unwrap(); + let query = Query::try_from("Q = (identifier)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ identifier "); } #[test] fn singleton_seq_is_one() { - let query = Query::try_from("{(identifier)}").unwrap(); + let query = Query::try_from("Q = {(identifier)}").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Seq¹ NamedNode¹ identifier "); @@ -26,11 +26,11 @@ fn singleton_seq_is_one() { #[test] fn nested_singleton_seq_is_one() { - let query = Query::try_from("{{{(identifier)}}}").unwrap(); + let query = Query::try_from("Q = {{{(identifier)}}}").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Seq¹ Seq¹ Seq¹ @@ -40,11 +40,11 @@ fn nested_singleton_seq_is_one() { #[test] fn multi_seq_is_many() { - let query = Query::try_from("{(a) (b)}").unwrap(); + let query = Query::try_from("Q = {(a) (b)}").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def⁺ + Def⁺ Q Seq⁺ NamedNode¹ a NamedNode¹ b @@ -53,11 +53,11 @@ fn multi_seq_is_many() { #[test] fn alt_is_one() { - let query = Query::try_from("[(a) (b)]").unwrap(); + let query = Query::try_from("Q = [(a) (b)]").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Alt¹ Branch¹ NamedNode¹ a @@ -69,13 +69,13 @@ fn alt_is_one() { #[test] fn alt_with_seq_branches() { let input = indoc! {r#" - [{(a) (b)} (c)] + Q = [{(a) (b)} (c)] "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Alt¹ Branch⁺ Seq⁺ @@ -90,7 +90,7 @@ fn alt_with_seq_branches() { fn ref_to_tree_is_one() { let input = indoc! {r#" X = (identifier) - (call (X)) + Q = (call (X)) "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); @@ -98,7 +98,7 @@ fn ref_to_tree_is_one() { Root⁺ Def¹ X NamedNode¹ identifier - Def¹ + Def¹ Q NamedNode¹ call Ref¹ X "); @@ -108,7 +108,7 @@ fn ref_to_tree_is_one() { fn ref_to_seq_is_many() { let input = indoc! {r#" X = {(a) (b)} - (call (X)) + Q = (call (X)) "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); @@ -118,7 +118,7 @@ fn ref_to_seq_is_many() { Seq⁺ NamedNode¹ a NamedNode¹ b - Def¹ + Def¹ Q NamedNode¹ call Ref⁺ X "); @@ -126,11 +126,11 @@ fn ref_to_seq_is_many() { #[test] fn field_with_tree() { - let query = Query::try_from("(call name: (identifier))").unwrap(); + let query = Query::try_from("Q = (call name: (identifier))").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ call FieldExpr¹ name: NamedNode¹ identifier @@ -139,11 +139,11 @@ fn field_with_tree() { #[test] fn field_with_alt() { - let query = Query::try_from("(call name: [(identifier) (string)])").unwrap(); + let query = Query::try_from("Q = (call name: [(identifier) (string)])").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ call FieldExpr¹ name: Alt¹ @@ -156,11 +156,11 @@ fn field_with_alt() { #[test] fn field_with_seq_error() { - let query = Query::try_from("(call name: {(a) (b)})").unwrap(); + let query = Query::try_from("Q = (call name: {(a) (b)})").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ call FieldExpr¹ name: Seq⁺ @@ -170,8 +170,8 @@ fn field_with_seq_error() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `name` must match exactly one node, not a sequence | - 1 | (call name: {(a) (b)}) - | ^^^^^^^^^ + 1 | Q = (call name: {(a) (b)}) + | ^^^^^^^^^ "); } @@ -179,7 +179,7 @@ fn field_with_seq_error() { fn field_with_ref_to_seq_error() { let input = indoc! {r#" X = {(a) (b)} - (call name: (X)) + Q = (call name: (X)) "#}; let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); @@ -189,7 +189,7 @@ fn field_with_ref_to_seq_error() { Seq⁺ NamedNode¹ a NamedNode¹ b - Def¹ + Def¹ Q NamedNode¹ call FieldExpr¹ name: Ref⁺ X @@ -197,18 +197,18 @@ fn field_with_ref_to_seq_error() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `name` must match exactly one node, not a sequence | - 2 | (call name: (X)) - | ^^^ + 2 | Q = (call name: (X)) + | ^^^ "); } #[test] fn quantifier_preserves_inner_arity() { - let query = Query::try_from("(identifier)*").unwrap(); + let query = Query::try_from("Q = (identifier)*").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q QuantifiedExpr¹ * NamedNode¹ identifier "); @@ -216,11 +216,11 @@ fn quantifier_preserves_inner_arity() { #[test] fn capture_preserves_inner_arity() { - let query = Query::try_from("(identifier) @name").unwrap(); + let query = Query::try_from("Q = (identifier) @name").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q CapturedExpr¹ @name NamedNode¹ identifier "); @@ -228,11 +228,11 @@ fn capture_preserves_inner_arity() { #[test] fn capture_on_seq() { - let query = Query::try_from("{(a) (b)} @items").unwrap(); + let query = Query::try_from("Q = {(a) (b)} @items").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def⁺ + Def⁺ Q CapturedExpr⁺ @items Seq⁺ NamedNode¹ a @@ -244,9 +244,9 @@ fn capture_on_seq() { fn complex_nested_arities() { let input = indoc! {r#" Stmt = [(expr_stmt) (return_stmt)] - (function_definition + Q = (function_definition name: (identifier) @name - body: (block (Stmt)* @stmts)) + body: (block (Stmt)* @stmts)) "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); @@ -258,7 +258,7 @@ fn complex_nested_arities() { NamedNode¹ expr_stmt Branch¹ NamedNode¹ return_stmt - Def¹ + Def¹ Q NamedNode¹ function_definition CapturedExpr¹ @name FieldExpr¹ name: @@ -274,13 +274,13 @@ fn complex_nested_arities() { #[test] fn tagged_alt_arities() { let input = indoc! {r#" - [Ident: (identifier) Num: (number)] + Q = [Ident: (identifier) Num: (number)] "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Alt¹ Branch¹ Ident: NamedNode¹ identifier @@ -291,11 +291,11 @@ fn tagged_alt_arities() { #[test] fn anchor_has_no_arity() { - let query = Query::try_from("(block . (statement))").unwrap(); + let query = Query::try_from("Q = (block . (statement))").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ block . NamedNode¹ statement @@ -304,11 +304,11 @@ fn anchor_has_no_arity() { #[test] fn negated_field_has_no_arity() { - let query = Query::try_from("(function !async)").unwrap(); + let query = Query::try_from("Q = (function !async)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ function NegatedField !async "); @@ -316,55 +316,57 @@ fn negated_field_has_no_arity() { #[test] fn tree_with_wildcard_type() { - let query = Query::try_from("(_)").unwrap(); + let query = Query::try_from("Q = (_)").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ (any) "); } #[test] fn bare_wildcard_is_one() { - let query = Query::try_from("_").unwrap(); + let query = Query::try_from("Q = _").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q AnonymousNode¹ (any) "); } #[test] fn empty_seq_is_one() { - let query = Query::try_from("{}").unwrap(); + let query = Query::try_from("Q = {}").unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Seq¹ "); } #[test] fn literal_is_one() { - let query = Query::try_from(r#""if""#).unwrap(); + let query = Query::try_from(r#"Q = "if""#).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r#" Root¹ - Def¹ + Def¹ Q AnonymousNode¹ "if" "#); } #[test] fn invalid_error_node() { - let query = Query::try_from("(foo %)").unwrap(); + let query = Query::try_from("Q = (foo %)").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_cst_with_arities(), @r#" Root¹ Def¹ + Id "Q" + Equals "=" Tree¹ ParenOpen "(" Id "foo" @@ -376,22 +378,22 @@ fn invalid_error_node() { #[test] fn invalid_undefined_ref() { - let query = Query::try_from("(Undefined)").unwrap(); + let query = Query::try_from("Q = (Undefined)").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def⁻ + Def⁻ Q Ref⁻ Undefined "); } #[test] fn invalid_branch_without_body() { - let query = Query::try_from("[A:]").unwrap(); + let query = Query::try_from("Q = [A:]").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q Alt¹ Branchˣ A: "); @@ -401,7 +403,7 @@ fn invalid_branch_without_body() { fn invalid_ref_to_bodyless_def() { let input = indoc! {r#" X = % - (X) + Q = (X) "#}; let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); @@ -409,7 +411,7 @@ fn invalid_ref_to_bodyless_def() { Root⁺ Defˣ X Defˣ - Def⁻ + Def⁻ Q Ref⁻ X "); } @@ -417,42 +419,42 @@ fn invalid_ref_to_bodyless_def() { #[test] fn invalid_capture_without_inner() { // Error recovery: `extra` is invalid, but `@y` still creates a Capture node - let query = Query::try_from("(call extra @y)").unwrap(); + let query = Query::try_from("Q = (call extra @y)").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ call CapturedExpr⁻ @y "); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: bare identifier is not a valid expression; wrap in parentheses: `(identifier)` | - 1 | (call extra @y) - | ^^^^^ + 1 | Q = (call extra @y) + | ^^^^^ "); } #[test] fn invalid_capture_without_inner_standalone() { // Standalone capture without preceding expression - let query = Query::try_from("@x").unwrap(); + let query = Query::try_from("Q = @x").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" - error: `@` must follow an expression to capture + error: expected an expression; after `=` in definition | - 1 | @x - | ^ + 1 | Q = @x + | ^ "); } #[test] fn invalid_multiple_captures_with_error() { - let query = Query::try_from("(call (Undefined) @x extra @y)").unwrap(); + let query = Query::try_from("Q = (call (Undefined) @x extra @y)").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ call CapturedExpr⁻ @x Ref⁻ Undefined @@ -463,18 +465,18 @@ fn invalid_multiple_captures_with_error() { #[test] fn invalid_quantifier_without_inner() { // Error recovery: `extra` is invalid, but `*` still creates a Quantifier node - let query = Query::try_from("(foo extra*)").unwrap(); + let query = Query::try_from("Q = (foo extra*)").unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_with_arities(), @r" Root¹ - Def¹ + Def¹ Q NamedNode¹ foo QuantifiedExpr⁻ * "); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: bare identifier is not a valid expression; wrap in parentheses: `(identifier)` | - 1 | (foo extra*) - | ^^^^^ + 1 | Q = (foo extra*) + | ^^^^^ "); } diff --git a/crates/plotnik-lib/src/query/link_tests.rs b/crates/plotnik-lib/src/query/link_tests.rs index b228d8f1..4df387f5 100644 --- a/crates/plotnik-lib/src/query/link_tests.rs +++ b/crates/plotnik-lib/src/query/link_tests.rs @@ -4,7 +4,7 @@ use indoc::indoc; #[test] fn valid_query_with_field() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration name: (identifier) @name) @fn "#}; @@ -15,7 +15,7 @@ fn valid_query_with_field() { assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @fn NamedNode function_declaration CapturedExpr @name @@ -27,7 +27,7 @@ fn valid_query_with_field() { #[test] fn unknown_node_type_with_suggestion() { let input = indoc! {r#" - (function_declaraton) @fn + Q = (function_declaraton) @fn "#}; let query = Query::try_from(input) @@ -38,8 +38,8 @@ fn unknown_node_type_with_suggestion() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `function_declaraton` is not a valid node type | - 1 | (function_declaraton) @fn - | ^^^^^^^^^^^^^^^^^^^ + 1 | Q = (function_declaraton) @fn + | ^^^^^^^^^^^^^^^^^^^ | help: did you mean `function_declaration`? "); @@ -48,7 +48,7 @@ fn unknown_node_type_with_suggestion() { #[test] fn unknown_node_type_no_suggestion() { let input = indoc! {r#" - (xyzzy_foobar_baz) @fn + Q = (xyzzy_foobar_baz) @fn "#}; let query = Query::try_from(input) @@ -59,15 +59,15 @@ fn unknown_node_type_no_suggestion() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `xyzzy_foobar_baz` is not a valid node type | - 1 | (xyzzy_foobar_baz) @fn - | ^^^^^^^^^^^^^^^^ + 1 | Q = (xyzzy_foobar_baz) @fn + | ^^^^^^^^^^^^^^^^ "); } #[test] fn unknown_field_with_suggestion() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration nme: (identifier) @name) @fn "#}; @@ -89,7 +89,7 @@ fn unknown_field_with_suggestion() { #[test] fn unknown_field_no_suggestion() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration xyzzy: (identifier) @name) @fn "#}; @@ -109,7 +109,7 @@ fn unknown_field_no_suggestion() { #[test] fn field_not_on_node_type() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration condition: (identifier) @name) @fn "#}; @@ -121,8 +121,8 @@ fn field_not_on_node_type() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `condition` is not valid on this node type | - 1 | (function_declaration - | -------------------- on `function_declaration` + 1 | Q = (function_declaration + | -------------------- on `function_declaration` 2 | condition: (identifier) @name) @fn | ^^^^^^^^^ | @@ -133,7 +133,7 @@ fn field_not_on_node_type() { #[test] fn field_not_on_node_type_with_suggestion() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration parameter: (formal_parameters) @params) @fn "#}; @@ -145,8 +145,8 @@ fn field_not_on_node_type_with_suggestion() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `parameter` is not valid on this node type | - 1 | (function_declaration - | -------------------- on `function_declaration` + 1 | Q = (function_declaration + | -------------------- on `function_declaration` 2 | parameter: (formal_parameters) @params) @fn | ^^^^^^^^^ | @@ -158,7 +158,7 @@ fn field_not_on_node_type_with_suggestion() { #[test] fn negated_field_unknown() { let input = indoc! {r#" - (function_declaration !nme) @fn + Q = (function_declaration !nme) @fn "#}; let query = Query::try_from(input) @@ -169,8 +169,8 @@ fn negated_field_unknown() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `nme` is not a valid field | - 1 | (function_declaration !nme) @fn - | ^^^ + 1 | Q = (function_declaration !nme) @fn + | ^^^ | help: did you mean `name`? "); @@ -179,7 +179,7 @@ fn negated_field_unknown() { #[test] fn negated_field_not_on_node_type() { let input = indoc! {r#" - (function_declaration !condition) @fn + Q = (function_declaration !condition) @fn "#}; let query = Query::try_from(input) @@ -190,10 +190,10 @@ fn negated_field_not_on_node_type() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `condition` is not valid on this node type | - 1 | (function_declaration !condition) @fn - | -------------------- ^^^^^^^^^ - | | - | on `function_declaration` + 1 | Q = (function_declaration !condition) @fn + | -------------------- ^^^^^^^^^ + | | + | on `function_declaration` | help: valid fields for `function_declaration`: `body`, `name`, `parameters` "); @@ -202,7 +202,7 @@ fn negated_field_not_on_node_type() { #[test] fn negated_field_not_on_node_type_with_suggestion() { let input = indoc! {r#" - (function_declaration !parameter) @fn + Q = (function_declaration !parameter) @fn "#}; let query = Query::try_from(input) @@ -213,10 +213,10 @@ fn negated_field_not_on_node_type_with_suggestion() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `parameter` is not valid on this node type | - 1 | (function_declaration !parameter) @fn - | -------------------- ^^^^^^^^^ - | | - | on `function_declaration` + 1 | Q = (function_declaration !parameter) @fn + | -------------------- ^^^^^^^^^ + | | + | on `function_declaration` | help: did you mean `parameters`? help: valid fields for `function_declaration`: `body`, `name`, `parameters`, `return_type`, `type_parameters` @@ -226,7 +226,7 @@ fn negated_field_not_on_node_type_with_suggestion() { #[test] fn negated_field_valid() { let input = indoc! {r#" - (function_declaration !name) @fn + Q = (function_declaration !name) @fn "#}; let query = Query::try_from(input) @@ -236,7 +236,7 @@ fn negated_field_valid() { assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @fn NamedNode function_declaration NegatedField !name @@ -246,7 +246,7 @@ fn negated_field_valid() { #[test] fn anonymous_node_unknown() { let input = indoc! {r#" - (function_declaration "xyzzy_fake_token") @fn + Q = (function_declaration "xyzzy_fake_token") @fn "#}; let query = Query::try_from(input) @@ -257,15 +257,15 @@ fn anonymous_node_unknown() { insta::assert_snapshot!(query.dump_diagnostics(), @r#" error: `xyzzy_fake_token` is not a valid node type | - 1 | (function_declaration "xyzzy_fake_token") @fn - | ^^^^^^^^^^^^^^^^ + 1 | Q = (function_declaration "xyzzy_fake_token") @fn + | ^^^^^^^^^^^^^^^^ "#); } #[test] fn error_and_missing_nodes_skip_validation() { let input = indoc! {r#" - (ERROR) @err + Q = (ERROR) @err "#}; let query = Query::try_from(input) @@ -275,7 +275,7 @@ fn error_and_missing_nodes_skip_validation() { assert!(query.is_valid()); let input2 = indoc! {r#" - (MISSING) @miss + Q = (MISSING) @miss "#}; let query2 = Query::try_from(input2) @@ -288,7 +288,7 @@ fn error_and_missing_nodes_skip_validation() { #[test] fn multiple_errors_in_query() { let input = indoc! {r#" - (function_declaraton + Q = (function_declaraton nme: (identifer) @name) @fn "#}; @@ -300,8 +300,8 @@ fn multiple_errors_in_query() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `function_declaraton` is not a valid node type | - 1 | (function_declaraton - | ^^^^^^^^^^^^^^^^^^^ + 1 | Q = (function_declaraton + | ^^^^^^^^^^^^^^^^^^^ | help: did you mean `function_declaration`? @@ -324,7 +324,7 @@ fn multiple_errors_in_query() { #[test] fn nested_field_validation() { let input = indoc! {r#" - (function_declaration + Q = (function_declaration body: (statement_block (return_statement) @ret) @body) @fn "#}; @@ -336,7 +336,7 @@ fn nested_field_validation() { assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @fn NamedNode function_declaration CapturedExpr @body @@ -350,7 +350,7 @@ fn nested_field_validation() { #[test] fn alternation_with_link_errors() { let input = indoc! {r#" - [(function_declaraton) + Q = [(function_declaraton) (class_declaraton)] @decl "#}; @@ -362,8 +362,8 @@ fn alternation_with_link_errors() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `function_declaraton` is not a valid node type | - 1 | [(function_declaraton) - | ^^^^^^^^^^^^^^^^^^^ + 1 | Q = [(function_declaraton) + | ^^^^^^^^^^^^^^^^^^^ | help: did you mean `function_declaration`? @@ -379,7 +379,7 @@ fn alternation_with_link_errors() { #[test] fn quantified_expr_validation() { let input = indoc! {r#" - (statement_block + Q = (statement_block (function_declaration)+ @fns) @block "#}; @@ -390,7 +390,7 @@ fn quantified_expr_validation() { assert!(query.is_valid()); insta::assert_snapshot!(query.dump_ast(), @r" Root - Def + Def Q CapturedExpr @block NamedNode statement_block CapturedExpr @fns @@ -402,7 +402,7 @@ fn quantified_expr_validation() { #[test] fn wildcard_node_skips_validation() { let input = indoc! {r#" - (_) @any + Q = (_) @any "#}; let query = Query::try_from(input) @@ -417,7 +417,7 @@ fn def_reference_with_link() { let input = indoc! {r#" Func = (function_declaration name: (identifier) @name) @fn - (program (Func)+) + Q = (program (Func)+) "#}; let query = Query::try_from(input) @@ -433,7 +433,7 @@ fn def_reference_with_link() { CapturedExpr @name FieldExpr name: NamedNode identifier - Def + Def Q NamedNode program QuantifiedExpr + Ref Func @@ -443,7 +443,7 @@ fn def_reference_with_link() { #[test] fn field_on_node_without_fields() { let input = indoc! {r#" - (identifier + Q = (identifier name: (identifier) @inner) @id "#}; @@ -455,8 +455,8 @@ fn field_on_node_without_fields() { insta::assert_snapshot!(query.dump_diagnostics(), @r" error: field `name` is not valid on this node type | - 1 | (identifier - | ---------- on `identifier` + 1 | Q = (identifier + | ---------- on `identifier` 2 | name: (identifier) @inner) @id | ^^^^ | @@ -467,7 +467,7 @@ fn field_on_node_without_fields() { #[test] fn valid_child_via_supertype() { let input = indoc! {r#" - (statement_block + Q = (statement_block (function_declaration)) @block "#}; @@ -481,7 +481,7 @@ fn valid_child_via_supertype() { #[test] fn valid_child_via_nested_supertype() { let input = indoc! {r#" - (program + Q = (program (function_declaration)) @prog "#}; @@ -495,7 +495,7 @@ fn valid_child_via_nested_supertype() { #[test] fn deeply_nested_sequences_valid() { let input = indoc! {r#" - (statement_block {{{(function_declaration)}}}) @block + Q = (statement_block {{{(function_declaration)}}}) @block "#}; let query = Query::try_from(input) @@ -508,7 +508,7 @@ fn deeply_nested_sequences_valid() { #[test] fn deeply_nested_alternations_in_field_valid() { let input = indoc! {r#" - (function_declaration name: [[[(identifier)]]]) @fn + Q = (function_declaration name: [[[(identifier)]]]) @fn "#}; let query = Query::try_from(input) @@ -522,7 +522,7 @@ fn deeply_nested_alternations_in_field_valid() { fn ref_followed_valid_case() { let input = indoc! {r#" Foo = (identifier) - (function_declaration name: (Foo)) + Q = (function_declaration name: (Foo)) "#}; let query = Query::try_from(input) @@ -536,7 +536,7 @@ fn ref_followed_valid_case() { fn ref_followed_recursive_valid() { let input = indoc! {r#" Foo = [(identifier) (Foo)] - (function_declaration name: (Foo)) + Q = (function_declaration name: (Foo)) "#}; let query = Query::try_from(input) diff --git a/crates/plotnik-lib/src/query/symbol_table_tests.rs b/crates/plotnik-lib/src/query/symbol_table_tests.rs index 979d8f9e..f01394a6 100644 --- a/crates/plotnik-lib/src/query/symbol_table_tests.rs +++ b/crates/plotnik-lib/src/query/symbol_table_tests.rs @@ -175,38 +175,38 @@ fn reference_in_capture() { fn entry_point_reference() { let input = indoc! {r#" Expr = (expression) - (call function: (Expr)) + Q = (call function: (Expr)) "#}; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); insta::assert_snapshot!(query.dump_symbols(), @r" Expr - _ + Q Expr "); } #[test] fn entry_point_undefined_reference() { - let input = "(call function: (Unknown))"; + let input = "Q = (call function: (Unknown))"; let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `Unknown` is not defined | - 1 | (call function: (Unknown)) - | ^^^^^^^ + 1 | Q = (call function: (Unknown)) + | ^^^^^^^ "); } #[test] fn no_definitions() { - let input = "(identifier)"; + let input = "Q = (identifier)"; let query = Query::try_from(input).unwrap(); assert!(query.is_valid()); - insta::assert_snapshot!(query.dump_symbols(), @"_"); + insta::assert_snapshot!(query.dump_symbols(), @"Q"); } #[test] @@ -237,25 +237,25 @@ fn nested_references() { #[test] fn multiple_undefined() { - let input = "(foo (X) (Y) (Z))"; + let input = "Q = (foo (X) (Y) (Z))"; let query = Query::try_from(input).unwrap(); assert!(!query.is_valid()); insta::assert_snapshot!(query.dump_diagnostics(), @r" error: `X` is not defined | - 1 | (foo (X) (Y) (Z)) - | ^ + 1 | Q = (foo (X) (Y) (Z)) + | ^ error: `Y` is not defined | - 1 | (foo (X) (Y) (Z)) - | ^ + 1 | Q = (foo (X) (Y) (Z)) + | ^ error: `Z` is not defined | - 1 | (foo (X) (Y) (Z)) - | ^ + 1 | Q = (foo (X) (Y) (Z)) + | ^ "); }