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 @@ -6,8 +6,8 @@ fn empty_tree() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `()` is not allowed
insta::assert_snapshot!(res, @"
error: empty `()` matches nothing
|
1 | Q = ()
| ^^
Expand All @@ -22,8 +22,8 @@ fn empty_tree_with_whitespace() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `()` is not allowed
insta::assert_snapshot!(res, @"
error: empty `()` matches nothing
|
1 | Q = ( )
| ^^^^^
Expand All @@ -38,8 +38,8 @@ fn empty_tree_with_comment() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `()` is not allowed
insta::assert_snapshot!(res, @"
error: empty `()` matches nothing
|
1 | Q = ( /* comment */ )
| ^^^^^^^^^^^^^^^^^
Expand All @@ -54,8 +54,8 @@ fn empty_sequence() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `{}` is not allowed
insta::assert_snapshot!(res, @"
error: empty `{}` matches nothing
|
1 | Q = {}
| ^^
Expand All @@ -70,8 +70,8 @@ fn empty_sequence_with_whitespace() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `{}` is not allowed
insta::assert_snapshot!(res, @"
error: empty `{}` matches nothing
|
1 | Q = { }
| ^^^^^
Expand All @@ -86,8 +86,8 @@ fn empty_sequence_with_comment() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `{}` is not allowed
insta::assert_snapshot!(res, @"
error: empty `{}` matches nothing
|
1 | Q = { /* comment */ }
| ^^^^^^^^^^^^^^^^^
Expand All @@ -102,8 +102,8 @@ fn empty_alternation() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `[]` is not allowed
insta::assert_snapshot!(res, @"
error: empty `[]` matches nothing
|
1 | Q = []
| ^^
Expand All @@ -118,8 +118,8 @@ fn empty_alternation_with_whitespace() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `[]` is not allowed
insta::assert_snapshot!(res, @"
error: empty `[]` matches nothing
|
1 | Q = [ ]
| ^^^^^
Expand All @@ -134,8 +134,8 @@ fn empty_alternation_with_comment() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `[]` is not allowed
insta::assert_snapshot!(res, @"
error: empty `[]` matches nothing
|
1 | Q = [ /* comment */ ]
| ^^^^^^^^^^^^^^^^^
Expand All @@ -150,8 +150,8 @@ fn nested_empty_sequence() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `{}` is not allowed
insta::assert_snapshot!(res, @"
error: empty `{}` matches nothing
|
1 | Q = (foo {})
| ^^
Expand All @@ -166,8 +166,8 @@ fn nested_empty_alternation() {

let res = Query::expect_invalid(input);

insta::assert_snapshot!(res, @r"
error: empty `[]` is not allowed
insta::assert_snapshot!(res, @"
error: empty `[]` matches nothing
|
1 | Q = (foo [])
| ^^
Expand Down
60 changes: 32 additions & 28 deletions crates/plotnik-compiler/src/diagnostics/diagnostics_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ fn builder_with_related() {
.emit();

assert_eq!(diagnostics.len(), 1);
let result = diagnostics.printer(&map).render();
insta::assert_snapshot!(result, @r"
error: missing closing `)`; primary
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @"
error: missing closing `)`: primary
|
1 | hello world!
| ^^^^^ ---- related info
Expand All @@ -87,9 +87,9 @@ fn builder_with_fix() {
.fix("apply this fix", "fixed")
.emit();

let result = diagnostics.printer(&map).render();
insta::assert_snapshot!(result, @r"
error: use `:` instead of `=`: fixable
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @"
error: fields use `:`, not `=`: fixable
|
1 | hello world
| ^^^^^
Expand Down Expand Up @@ -120,9 +120,9 @@ fn builder_with_all_options() {
.fix("try this", "HELLO")
.emit();

let result = diagnostics.printer(&map).render();
insta::assert_snapshot!(result, @r"
error: missing closing `)`; main error
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @"
error: missing closing `)`: main error
|
1 | hello world stuff!
| ^^^^^ ----- ----- and here
Expand Down Expand Up @@ -152,7 +152,7 @@ fn printer_colored() {
.message("test")
.emit();

let result = diagnostics.printer(&map).colored(true).render();
let result = diagnostics.render_colored(&map, true);
assert!(result.contains("test"));
assert!(result.contains('\x1b'));
}
Expand All @@ -161,7 +161,7 @@ fn printer_colored() {
fn printer_empty_diagnostics() {
let map = SourceMap::one_liner("source");
let diagnostics = Diagnostics::new();
let result = diagnostics.printer(&map).render();
let result = diagnostics.render_unfiltered(&map);
assert!(result.is_empty());
}

Expand All @@ -180,7 +180,7 @@ fn printer_with_custom_path() {
.message("test error")
.emit();

let result = diagnostics.printer(&map).render();
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @r"
error: `test error` is not defined
--> test.pql:1:1
Expand All @@ -205,7 +205,7 @@ fn printer_zero_width_span() {
.message("zero width error")
.emit();

let result = diagnostics.printer(&map).render();
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @r"
error: expected an expression: zero width error
|
Expand All @@ -230,9 +230,9 @@ fn printer_related_zero_width() {
.related_to(id, TextRange::empty(6.into()), "zero width related")
.emit();

let result = diagnostics.printer(&map).render();
insta::assert_snapshot!(result, @r"
error: missing closing `)`; primary
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @"
error: missing closing `)`: primary
|
1 | hello world!
| ^^^^^ - zero width related
Expand Down Expand Up @@ -262,9 +262,9 @@ fn printer_multiple_diagnostics() {
.message("second error")
.emit();

let result = diagnostics.printer(&map).render();
insta::assert_snapshot!(result, @r"
error: missing closing `)`; first error
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @"
error: missing closing `)`: first error
|
1 | hello world!
| ^^^^^
Expand Down Expand Up @@ -347,14 +347,18 @@ fn diagnostic_kind_fallback_messages() {

#[test]
fn diagnostic_kind_custom_messages() {
assert_eq!(
DiagnosticKind::UnclosedTree.custom_message(),
"missing closing `)`; {}"
);
// Detail replaces the whole message
assert_eq!(DiagnosticKind::UnexpectedToken.custom_message(), "{}");
// Detail is interpolated into a template
assert_eq!(
DiagnosticKind::UndefinedReference.custom_message(),
"`{}` is not defined"
);
// Default: fallback message plus detail
assert_eq!(
DiagnosticKind::DuplicateCaptureInScope.custom_message(),
"capture `@{}` already defined in this scope"
);
}

#[test]
Expand All @@ -366,8 +370,8 @@ fn diagnostic_kind_message_rendering() {
);
// With custom message → template applied
assert_eq!(
DiagnosticKind::UnclosedTree.message(Some("expected `)`")),
"missing closing `)`; expected `)`"
DiagnosticKind::UnexpectedToken.message(Some("expected `)`")),
"expected `)`"
);
assert_eq!(
DiagnosticKind::UndefinedReference.message(Some("Foo")),
Expand Down Expand Up @@ -514,7 +518,7 @@ fn render_filtered() {
.message("unnamed def")
.emit();

let result = diagnostics.render_filtered(&map);
let result = diagnostics.render(&map);
// Should only show the unclosed tree error
assert!(result.contains("unclosed tree"));
assert!(!result.contains("unnamed def"));
Expand All @@ -539,7 +543,7 @@ fn multi_file_cross_file_related() {
.related_to(file_a, TextRange::new(0.into(), 3.into()), "defined here")
.emit();

let result = diagnostics.printer(&map).render();
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @r"
error: `Foo` is not defined
--> b.ptk:1:2
Expand Down Expand Up @@ -574,7 +578,7 @@ fn multi_file_same_file_related() {
)
.emit();

let result = diagnostics.printer(&map).render();
let result = diagnostics.render_unfiltered(&map);
insta::assert_snapshot!(result, @r"
error: `Foo` is already defined
--> main.ptk:1:13
Expand Down
Loading