Skip to content

Commit 6eb50aa

Browse files
committed
Test diagnostic ranges, instead of only the start
1 parent 4cf044b commit 6eb50aa

File tree

4 files changed

+158
-69
lines changed

4 files changed

+158
-69
lines changed

docs/testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ The syntax tests are testing that the compiler show the right error messages in
1010
The syntax tests are located in [internal/compiler/tests/syntax/](../internal/compiler/tests/syntax/) and it's driven by the
1111
[`syntax_tests.rs`](../internal/compiler/tests/syntax_tests.rs) file. More info in the comments of that file.
1212

13-
In summary, each .slint files have comments with `^error` like so:
13+
In summary, each .slint files have comments with `> <error` like so:
1414

1515
```ignore
1616
foo bar
17-
// ^error{parse error}
17+
// > <error{parse error}
1818
```
1919

20-
Meaning that there must be an error on the line above at the location pointed by the caret.
20+
Meaning that there must be an error on the line above spanning `bar`, as indicated by the `>` and `<` arrows.
2121

2222
Ideally, each error message must be tested like so.
2323

internal/compiler/parser.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,7 @@ impl Parser for DefaultParser<'_> {
694694
fn error(&mut self, e: impl Into<String>) {
695695
let current_token = self.current_token();
696696
#[allow(unused_mut)]
697-
let mut span = crate::diagnostics::Span::new(
698-
current_token.offset,
699-
current_token.length);
697+
let mut span = crate::diagnostics::Span::new(current_token.offset, current_token.length);
700698
#[cfg(feature = "proc_macro_span")]
701699
{
702700
span.span = current_token.span;
@@ -715,9 +713,7 @@ impl Parser for DefaultParser<'_> {
715713
fn warning(&mut self, e: impl Into<String>) {
716714
let current_token = self.current_token();
717715
#[allow(unused_mut)]
718-
let mut span = crate::diagnostics::Span::new(
719-
current_token.offset,
720-
current_token.length);
716+
let mut span = crate::diagnostics::Span::new(current_token.offset, current_token.length);
721717
#[cfg(feature = "proc_macro_span")]
722718
{
723719
span.span = current_token.span;
@@ -953,9 +949,7 @@ impl NodeOrToken {
953949
impl Spanned for SyntaxNode {
954950
fn span(&self) -> crate::diagnostics::Span {
955951
let range = self.node.text_range();
956-
crate::diagnostics::Span::new(
957-
range.start().into(),
958-
range.len().into())
952+
crate::diagnostics::Span::new(range.start().into(), range.len().into())
959953
}
960954

961955
fn source_file(&self) -> Option<&SourceFile> {
@@ -976,9 +970,7 @@ impl Spanned for Option<SyntaxNode> {
976970
impl Spanned for SyntaxToken {
977971
fn span(&self) -> crate::diagnostics::Span {
978972
let range = self.token.text_range();
979-
crate::diagnostics::Span::new(
980-
range.start().into(),
981-
range.len().into())
973+
crate::diagnostics::Span::new(range.start().into(), range.len().into())
982974
}
983975

984976
fn source_file(&self) -> Option<&SourceFile> {

internal/compiler/tests/syntax/expressions/noops.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ enum MyEnum {
1414
export component Test {
1515
function useless_if(cond: bool) {
1616
if (cond) {
17-
// ^warning{Expression has no effect!}
17+
// >warning{Expression has no effect!}
1818
if (!cond) {
19-
// ^warning{Expression has no effect!}
19+
// >warning{Expression has no effect!}
2020
43
2121
}
22+
// <warning{Expression has no effect!}
2223
42
2324
}
2425
else {
2526
41
2627
}
28+
// <warning{Expression has no effect!}
2729
"hello world";
2830
// ^warning{Expression has no effect!}
2931
123;

0 commit comments

Comments
 (0)