Add test for overlapping multiline labels

This commit is contained in:
Brendan Zabarauskas
2020-03-23 15:25:55 +11:00
parent 4e7153985e
commit 1debd7a352
5 changed files with 125 additions and 0 deletions
@@ -0,0 +1,33 @@
---
source: codespan-reporting/tests/term.rs
expression: TEST_DATA.emit_color(&config)
---
{fg:Red bold bright}error[E0308]{bold bright}: match arms have incompatible types{/}
{fg:Blue}┌──{/} codespan/src/file.rs:1:9 {fg:Blue}───{/}
{fg:Blue}│{/}
{fg:Blue}1{/} {fg:Blue}│{/} {fg:Blue}╭{/} match line_index.compare(self.last_line_index()) {
{fg:Blue}2{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
{fg:Blue}3{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Equal => Ok(self.source_span().end()),
{fg:Blue}4{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Greater => LineIndexOutOfBoundsError {
{fg:Blue}5{/} {fg:Blue}│{/} {fg:Blue}│{/} given: line_index,
{fg:Blue}6{/} {fg:Blue}│{/} {fg:Blue}│{/} max: self.last_line_index(),
{fg:Blue}7{/} {fg:Blue}│{/} {fg:Blue}│{/} },
{fg:Blue}8{/} {fg:Blue}│{/} {fg:Blue}│{/} }
{fg:Blue}│{/} {fg:Blue}╰{/}{fg:Blue}─────────' `match` arms have incompatible types{/}
{fg:Blue}·{/}
{fg:Blue}2{/} {fg:Blue}│{/} Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
{fg:Blue}│{/} {fg:Blue}--------------------------------------------- this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`{/}
{fg:Blue}3{/} {fg:Blue}│{/} Ordering::Equal => Ok(self.source_span().end()),
{fg:Blue}│{/} {fg:Blue}---------------------------- this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`{/}
{fg:Blue}4{/} {fg:Blue}│{/} Ordering::Greater => LineIndexOutOfBoundsError {
{fg:Blue}│{/} {fg:Red}╭{/}{fg:Red}──────────────────────────────────^{/}
{fg:Blue}5{/} {fg:Blue}│{/} {fg:Red}│{/} given: line_index,
{fg:Blue}6{/} {fg:Blue}│{/} {fg:Red}│{/} max: self.last_line_index(),
{fg:Blue}7{/} {fg:Blue}│{/} {fg:Red}│{/} },
{fg:Blue}│{/} {fg:Red}╰{/}{fg:Red}─────────────^ expected enum `Result`, found struct `LineIndexOutOfBoundsError`{/}
{fg:Blue}│{/}
{fg:Blue}={/} expected type `Result<ByteIndex, LineIndexOutOfBoundsError>`
found type `LineIndexOutOfBoundsError`
@@ -0,0 +1,33 @@
---
source: codespan-reporting/tests/term.rs
expression: TEST_DATA.emit_no_color(&config)
---
error[E0308]: match arms have incompatible types
┌── codespan/src/file.rs:1:9 ───
1 │ ╭ match line_index.compare(self.last_line_index()) {
2 │ │ Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
3 │ │ Ordering::Equal => Ok(self.source_span().end()),
4 │ │ Ordering::Greater => LineIndexOutOfBoundsError {
5 │ │ given: line_index,
6 │ │ max: self.last_line_index(),
7 │ │ },
8 │ │ }
│ ╰─────────' `match` arms have incompatible types
·
2 │ Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),
│ --------------------------------------------- this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`
3 │ Ordering::Equal => Ok(self.source_span().end()),
│ ---------------------------- this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`
4 │ Ordering::Greater => LineIndexOutOfBoundsError {
│ ╭──────────────────────────────────^
5 │ │ given: line_index,
6 │ │ max: self.last_line_index(),
7 │ │ },
│ ╰─────────────^ expected enum `Result`, found struct `LineIndexOutOfBoundsError`
= expected type `Result<ByteIndex, LineIndexOutOfBoundsError>`
found type `LineIndexOutOfBoundsError`
@@ -0,0 +1,6 @@
---
source: codespan-reporting/tests/term.rs
expression: TEST_DATA.emit_color(&config)
---
codespan/src/file.rs:4:34: {fg:Red bold bright}error[E0308]{bold bright}: match arms have incompatible types{/}
@@ -0,0 +1,6 @@
---
source: codespan-reporting/tests/term.rs
expression: TEST_DATA.emit_no_color(&config)
---
codespan/src/file.rs:4:34: error[E0308]: match arms have incompatible types
+47
View File
@@ -365,6 +365,53 @@ mod fizz_buzz {
test_emit!(short_no_color);
}
mod multiline_overlapping {
use super::*;
lazy_static::lazy_static! {
static ref TEST_DATA: TestData<'static, SimpleFile<&'static str, String>> = {
let file = SimpleFile::new(
"codespan/src/file.rs",
[
" match line_index.compare(self.last_line_index()) {",
" Ordering::Less => Ok(self.line_starts()[line_index.to_usize()]),",
" Ordering::Equal => Ok(self.source_span().end()),",
" Ordering::Greater => LineIndexOutOfBoundsError {",
" given: line_index,",
" max: self.last_line_index(),",
" },",
" }",
].join("\n")
);
let diagnostics = vec![
Diagnostic::error()
.with_message("match arms have incompatible types")
.with_code("E0308")
.with_labels(vec![
Label::primary((), 230..351).with_message("expected enum `Result`, found struct `LineIndexOutOfBoundsError`"),
Label::secondary((), 8..362).with_message("`match` arms have incompatible types"),
Label::secondary((), 89..134).with_message("this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`"),
Label::secondary((), 167..195).with_message("this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`"),
])
.with_notes(vec![unindent::unindent(
"
expected type `Result<ByteIndex, LineIndexOutOfBoundsError>`
found type `LineIndexOutOfBoundsError`
"
)]),
];
TestData { files: file, diagnostics }
};
}
test_emit!(rich_color);
test_emit!(short_color);
test_emit!(rich_no_color);
test_emit!(short_no_color);
}
mod tabbed {
use super::*;