2020-04-27 12:56:11 -05:00
|
|
|
use rustc_ast as ast;
|
2020-02-29 11:37:32 -06:00
|
|
|
use rustc_ast::tokenstream::TokenStream;
|
2019-12-22 16:42:04 -06:00
|
|
|
use rustc_parse::{new_parser_from_source_str, parser::Parser, source_file_to_stream};
|
2020-01-18 12:21:05 -06:00
|
|
|
use rustc_session::parse::ParseSess;
|
2020-01-01 12:25:28 -06:00
|
|
|
use rustc_span::source_map::{FilePathMapping, SourceMap};
|
2020-07-29 20:27:50 -05:00
|
|
|
use rustc_span::with_default_session_globals;
|
2019-12-31 11:15:40 -06:00
|
|
|
use rustc_span::{BytePos, MultiSpan, Span};
|
2019-02-08 20:24:02 -06:00
|
|
|
|
2019-08-01 16:26:40 -05:00
|
|
|
use rustc_data_structures::sync::Lrc;
|
2020-01-09 04:18:47 -06:00
|
|
|
use rustc_errors::emitter::EmitterWriter;
|
|
|
|
use rustc_errors::{Handler, PResult};
|
2019-02-06 11:33:01 -06:00
|
|
|
|
2016-10-23 19:22:06 -05:00
|
|
|
use std::io;
|
|
|
|
use std::io::prelude::*;
|
2019-08-01 16:26:40 -05:00
|
|
|
use std::iter::Peekable;
|
|
|
|
use std::path::{Path, PathBuf};
|
2016-10-23 19:22:06 -05:00
|
|
|
use std::str;
|
|
|
|
use std::sync::{Arc, Mutex};
|
2019-08-01 16:26:40 -05:00
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
/// Map string to parser (via tts).
|
2019-08-01 16:26:40 -05:00
|
|
|
fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
|
|
|
|
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
|
|
|
|
}
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
crate fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T
|
|
|
|
where
|
2019-08-01 16:26:40 -05:00
|
|
|
F: FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
|
|
|
|
{
|
|
|
|
let mut p = string_to_parser(&ps, s);
|
2019-10-16 12:22:56 -05:00
|
|
|
let x = f(&mut p).unwrap();
|
2019-08-01 16:26:40 -05:00
|
|
|
p.sess.span_diagnostic.abort_if_errors();
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
/// Maps a string to tts, using a made-up filename.
|
2019-08-01 16:26:40 -05:00
|
|
|
crate fn string_to_stream(source_str: String) -> TokenStream {
|
2019-11-19 20:38:31 -06:00
|
|
|
let ps = ParseSess::new(FilePathMapping::empty());
|
2019-08-01 16:26:40 -05:00
|
|
|
source_file_to_stream(
|
|
|
|
&ps,
|
2019-12-22 16:42:04 -06:00
|
|
|
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.0
|
2019-08-01 16:26:40 -05:00
|
|
|
}
|
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
/// Parses a string, returns a crate.
|
2019-12-22 16:42:04 -06:00
|
|
|
crate fn string_to_crate(source_str: String) -> ast::Crate {
|
2019-11-19 20:38:31 -06:00
|
|
|
let ps = ParseSess::new(FilePathMapping::empty());
|
2019-12-22 16:42:04 -06:00
|
|
|
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
|
2019-08-01 16:26:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Does the given string match the pattern? whitespace in the first string
|
|
|
|
/// may be deleted or replaced with other whitespace to match the pattern.
|
|
|
|
/// This function is relatively Unicode-ignorant; fortunately, the careful design
|
|
|
|
/// of UTF-8 mitigates this ignorance. It doesn't do NKF-normalization(?).
|
2019-12-22 16:42:04 -06:00
|
|
|
crate fn matches_codepattern(a: &str, b: &str) -> bool {
|
2019-08-01 16:26:40 -05:00
|
|
|
let mut a_iter = a.chars().peekable();
|
|
|
|
let mut b_iter = b.chars().peekable();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let (a, b) = match (a_iter.peek(), b_iter.peek()) {
|
|
|
|
(None, None) => return true,
|
|
|
|
(None, _) => return false,
|
|
|
|
(Some(&a), None) => {
|
2019-09-04 05:16:36 -05:00
|
|
|
if rustc_lexer::is_whitespace(a) {
|
2019-12-22 16:42:04 -06:00
|
|
|
break; // Trailing whitespace check is out of loop for borrowck.
|
2019-08-01 16:26:40 -05:00
|
|
|
} else {
|
2019-12-22 16:42:04 -06:00
|
|
|
return false;
|
2019-08-01 16:26:40 -05:00
|
|
|
}
|
|
|
|
}
|
2019-12-22 16:42:04 -06:00
|
|
|
(Some(&a), Some(&b)) => (a, b),
|
2019-08-01 16:26:40 -05:00
|
|
|
};
|
|
|
|
|
2019-09-04 05:16:36 -05:00
|
|
|
if rustc_lexer::is_whitespace(a) && rustc_lexer::is_whitespace(b) {
|
2019-09-05 21:56:45 -05:00
|
|
|
// Skip whitespace for `a` and `b`.
|
2019-08-01 16:26:40 -05:00
|
|
|
scan_for_non_ws_or_end(&mut a_iter);
|
|
|
|
scan_for_non_ws_or_end(&mut b_iter);
|
2019-09-04 05:16:36 -05:00
|
|
|
} else if rustc_lexer::is_whitespace(a) {
|
2019-09-05 21:56:45 -05:00
|
|
|
// Skip whitespace for `a`.
|
2019-08-01 16:26:40 -05:00
|
|
|
scan_for_non_ws_or_end(&mut a_iter);
|
|
|
|
} else if a == b {
|
|
|
|
a_iter.next();
|
|
|
|
b_iter.next();
|
|
|
|
} else {
|
2019-12-22 16:42:04 -06:00
|
|
|
return false;
|
2019-08-01 16:26:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
// Check if a has *only* trailing whitespace.
|
2019-09-04 05:16:36 -05:00
|
|
|
a_iter.all(rustc_lexer::is_whitespace)
|
2019-08-01 16:26:40 -05:00
|
|
|
}
|
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
/// Advances the given peekable `Iterator` until it reaches a non-whitespace character.
|
2019-08-01 16:26:40 -05:00
|
|
|
fn scan_for_non_ws_or_end<I: Iterator<Item = char>>(iter: &mut Peekable<I>) {
|
2020-12-29 21:19:09 -06:00
|
|
|
while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) {
|
2019-08-01 16:26:40 -05:00
|
|
|
iter.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:56:45 -05:00
|
|
|
/// Identifies a position in the text by the n'th occurrence of a string.
|
2016-10-23 19:22:06 -05:00
|
|
|
struct Position {
|
|
|
|
string: &'static str,
|
|
|
|
count: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpanLabel {
|
|
|
|
start: Position,
|
|
|
|
end: Position,
|
|
|
|
label: &'static str,
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:55:31 -05:00
|
|
|
crate struct Shared<T: Write> {
|
|
|
|
pub data: Arc<Mutex<T>>,
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Write> Write for Shared<T> {
|
|
|
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
|
|
self.data.lock().unwrap().write(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> io::Result<()> {
|
|
|
|
self.data.lock().unwrap().flush()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &str) {
|
2020-07-05 19:53:14 -05:00
|
|
|
with_default_session_globals(|| {
|
2018-03-06 19:44:10 -06:00
|
|
|
let output = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
|
2018-10-29 15:26:13 -05:00
|
|
|
let source_map = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
|
|
|
source_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned());
|
2018-03-06 19:44:10 -06:00
|
|
|
|
|
|
|
let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end);
|
|
|
|
let mut msp = MultiSpan::from_span(primary_span);
|
|
|
|
for span_label in span_labels {
|
|
|
|
let span = make_span(&file_text, &span_label.start, &span_label.end);
|
|
|
|
msp.push_span_label(span, span_label.label.to_string());
|
|
|
|
println!("span: {:?} label: {:?}", span, span_label.label);
|
2018-10-29 15:26:13 -05:00
|
|
|
println!("text: {:?}", source_map.span_to_snippet(span));
|
2018-03-06 19:44:10 -06:00
|
|
|
}
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-08-14 19:57:28 -05:00
|
|
|
let emitter = EmitterWriter::new(
|
|
|
|
Box::new(Shared { data: output.clone() }),
|
|
|
|
Some(source_map.clone()),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
None,
|
2019-09-07 08:57:11 -05:00
|
|
|
false,
|
2019-08-14 19:57:28 -05:00
|
|
|
);
|
2019-03-07 13:15:47 -06:00
|
|
|
let handler = Handler::with_emitter(true, None, Box::new(emitter));
|
2018-03-06 19:44:10 -06:00
|
|
|
handler.span_err(msp, "foo");
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
assert!(
|
|
|
|
expected_output.chars().next() == Some('\n'),
|
|
|
|
"expected output should begin with newline"
|
|
|
|
);
|
2018-03-06 19:44:10 -06:00
|
|
|
let expected_output = &expected_output[1..];
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2018-03-06 19:44:10 -06:00
|
|
|
let bytes = output.lock().unwrap();
|
|
|
|
let actual_output = str::from_utf8(&bytes).unwrap();
|
|
|
|
println!("expected output:\n------\n{}------", expected_output);
|
|
|
|
println!("actual output:\n------\n{}------", actual_output);
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2018-03-06 19:44:10 -06:00
|
|
|
assert!(expected_output == actual_output)
|
|
|
|
})
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_span(file_text: &str, start: &Position, end: &Position) -> Span {
|
|
|
|
let start = make_pos(file_text, start);
|
|
|
|
let end = make_pos(file_text, end) + end.string.len(); // just after matching thing ends
|
|
|
|
assert!(start <= end);
|
2019-08-10 17:44:55 -05:00
|
|
|
Span::with_root_ctxt(BytePos(start as u32), BytePos(end as u32))
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_pos(file_text: &str, pos: &Position) -> usize {
|
|
|
|
let mut remainder = file_text;
|
|
|
|
let mut offset = 0;
|
|
|
|
for _ in 0..pos.count {
|
|
|
|
if let Some(n) = remainder.find(&pos.string) {
|
|
|
|
offset += n;
|
|
|
|
remainder = &remainder[n + 1..];
|
|
|
|
} else {
|
2019-12-22 16:42:04 -06:00
|
|
|
panic!("failed to find {} instances of {:?} in {:?}", pos.count, pos.string, file_text);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
offset
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ends_on_col0() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![SpanLabel {
|
|
|
|
start: Position { string: "{", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "test",
|
|
|
|
}],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:2:10
|
|
|
|
|
|
|
|
|
2 | fn foo() {
|
2017-04-14 18:38:10 -05:00
|
|
|
| __________^
|
2016-10-23 19:22:06 -05:00
|
|
|
3 | | }
|
2017-04-14 18:38:10 -05:00
|
|
|
| |_^ test
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ends_on_col2() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![SpanLabel {
|
|
|
|
start: Position { string: "{", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
2016-10-23 19:22:06 -05:00
|
|
|
label: "test",
|
2019-12-22 16:42:04 -06:00
|
|
|
}],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:2:10
|
|
|
|
|
|
|
|
|
2 | fn foo() {
|
2017-04-14 18:38:10 -05:00
|
|
|
| __________^
|
2016-10-23 19:22:06 -05:00
|
|
|
3 | |
|
|
|
|
4 | |
|
|
|
|
5 | | }
|
2017-04-14 18:38:10 -05:00
|
|
|
| |___^ test
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn non_nested() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0
|
|
|
|
X1 Y1
|
|
|
|
X2 Y2
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "Y2", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | X0 Y0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ____^__-
|
2016-10-23 19:22:06 -05:00
|
|
|
| | ___|
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||
|
2016-10-23 19:22:06 -05:00
|
|
|
4 | || X1 Y1
|
|
|
|
5 | || X2 Y2
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||____^__- `Y` is a good letter too
|
2016-10-23 19:22:06 -05:00
|
|
|
| |____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| `X` is a good letter
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nested() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0
|
|
|
|
Y1 X1
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X1", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "Y1", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | X0 Y0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ____^__-
|
2016-10-23 19:22:06 -05:00
|
|
|
| | ___|
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||
|
2016-10-23 19:22:06 -05:00
|
|
|
4 | || Y1 X1
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||____-__^ `X` is a good letter
|
2016-10-23 19:22:06 -05:00
|
|
|
| |_____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| `Y` is a good letter too
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn different_overlap() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Z1", count: 1 },
|
|
|
|
end: Position { string: "X3", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:6
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______^
|
2016-10-23 19:22:06 -05:00
|
|
|
4 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |_________-
|
2016-10-23 19:22:06 -05:00
|
|
|
5 | || X2 Y2 Z2
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||____^ `X` is a good letter
|
2016-10-23 19:22:06 -05:00
|
|
|
6 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |_____- `Y` is a good letter too
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn triple_overlap() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "Y2", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Z0", count: 1 },
|
|
|
|
end: Position { string: "Z2", count: 1 },
|
|
|
|
label: "`Z` label",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| _____^__-__-
|
2016-10-23 19:22:06 -05:00
|
|
|
| | ____|__|
|
2017-04-14 18:38:10 -05:00
|
|
|
| || ___|
|
|
|
|
| |||
|
2016-10-23 19:22:06 -05:00
|
|
|
4 | ||| X1 Y1 Z1
|
|
|
|
5 | ||| X2 Y2 Z2
|
2017-04-14 18:38:10 -05:00
|
|
|
| |||____^__-__- `Z` label
|
2016-10-23 19:22:06 -05:00
|
|
|
| ||____|__|
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____| `Y` is a good letter too
|
|
|
|
| `X` is a good letter
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
|
|
|
|
2019-03-27 21:26:47 -05:00
|
|
|
#[test]
|
|
|
|
fn triple_exact_overlap() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2019-03-27 21:26:47 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X2", count: 1 },
|
|
|
|
label: "`Z` label",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2019-03-27 21:26:47 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | / X0 Y0 Z0
|
|
|
|
4 | | X1 Y1 Z1
|
|
|
|
5 | | X2 Y2 Z2
|
|
|
|
| | ^
|
|
|
|
| | |
|
|
|
|
| | `X` is a good letter
|
|
|
|
| |____`Y` is a good letter too
|
|
|
|
| `Z` label
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2019-03-27 21:26:47 -05:00
|
|
|
}
|
|
|
|
|
2016-10-23 19:22:06 -05:00
|
|
|
#[test]
|
|
|
|
fn minimum_depth() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "X1", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y1", count: 1 },
|
|
|
|
end: Position { string: "Z2", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X2", count: 1 },
|
|
|
|
end: Position { string: "Y3", count: 1 },
|
|
|
|
label: "`Z`",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-10-23 19:22:06 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:6
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______^
|
2016-10-23 19:22:06 -05:00
|
|
|
4 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____^_-
|
2016-10-23 19:22:06 -05:00
|
|
|
| ||____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| | `X` is a good letter
|
2016-10-23 19:22:06 -05:00
|
|
|
5 | | X2 Y2 Z2
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____-______- `Y` is a good letter too
|
2016-10-23 19:22:06 -05:00
|
|
|
| ____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| |
|
2016-10-23 19:22:06 -05:00
|
|
|
6 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |________- `Z`
|
2016-10-23 19:22:06 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-10-23 19:22:06 -05:00
|
|
|
}
|
2016-11-23 01:32:16 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn non_overlaping() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-11-23 01:32:16 -06:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "X0", count: 1 },
|
|
|
|
end: Position { string: "X1", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y2", count: 1 },
|
|
|
|
end: Position { string: "Z3", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-11-23 01:32:16 -06:00
|
|
|
error: foo
|
2017-04-14 18:38:10 -05:00
|
|
|
--> test.rs:3:3
|
2016-11-23 01:32:16 -06:00
|
|
|
|
|
2017-04-14 18:38:10 -05:00
|
|
|
3 | / X0 Y0 Z0
|
2016-11-23 01:32:16 -06:00
|
|
|
4 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____^ `X` is a good letter
|
2016-11-23 01:32:16 -06:00
|
|
|
5 | X2 Y2 Z2
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______-
|
2016-11-23 01:32:16 -06:00
|
|
|
6 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |__________- `Y` is a good letter too
|
2016-11-23 01:32:16 -06:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-11-23 01:32:16 -06:00
|
|
|
}
|
2017-01-20 20:57:21 -06:00
|
|
|
|
2016-11-23 01:32:16 -06:00
|
|
|
#[test]
|
|
|
|
fn overlaping_start_and_end() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2016-11-23 01:32:16 -06:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
X2 Y2 Z2
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "X1", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Z1", count: 1 },
|
|
|
|
end: Position { string: "Z3", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2016-11-23 01:32:16 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:6
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______^
|
2016-11-23 01:32:16 -06:00
|
|
|
4 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____^____-
|
2016-11-23 01:32:16 -06:00
|
|
|
| ||____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| | `X` is a good letter
|
2016-11-23 01:32:16 -06:00
|
|
|
5 | | X2 Y2 Z2
|
|
|
|
6 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |___________- `Y` is a good letter too
|
2016-11-23 01:32:16 -06:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2016-11-23 01:32:16 -06:00
|
|
|
}
|
2017-01-20 20:57:21 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_primary_without_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "`a` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "c", count: 1 },
|
|
|
|
end: Position { string: "c", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:7
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ----^^^^-^^-- `a` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_secondary_without_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "`a` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^-------^^ `a` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_primary_without_message_2() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "`b` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "c", count: 1 },
|
|
|
|
end: Position { string: "c", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:7
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ----^^^^-^^--
|
|
|
|
| |
|
|
|
|
| `b` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_secondary_without_message_2() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "`b` is a good letter",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^-------^^
|
|
|
|
| |
|
|
|
|
| `b` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
2017-06-12 17:54:04 -05:00
|
|
|
#[test]
|
|
|
|
fn multiple_labels_secondary_without_message_3() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-06-12 17:54:04 -05:00
|
|
|
fn foo() {
|
|
|
|
a bc d
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "b", count: 1 },
|
|
|
|
label: "`a` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "c", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-06-12 17:54:04 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a bc d
|
|
|
|
| ^^^^----
|
|
|
|
| |
|
|
|
|
| `a` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-06-12 17:54:04 -05:00
|
|
|
}
|
|
|
|
|
2017-01-20 20:57:21 -06:00
|
|
|
#[test]
|
|
|
|
fn multiple_labels_without_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^-------^^
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_without_message_2() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "c", count: 1 },
|
|
|
|
end: Position { string: "c", count: 1 },
|
|
|
|
label: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:7
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ----^^^^-^^--
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_labels_with_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
|
|
|
label: "`a` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "b", count: 1 },
|
|
|
|
end: Position { string: "}", count: 1 },
|
|
|
|
label: "`b` is a good letter",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^-------^^
|
|
|
|
| | |
|
|
|
|
| | `b` is a good letter
|
|
|
|
| `a` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn single_label_with_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
2017-01-20 20:57:21 -06:00
|
|
|
label: "`a` is a good letter",
|
2019-12-22 16:42:04 -06:00
|
|
|
}],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^^^^^^^^^^ `a` is a good letter
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn single_label_without_message() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
fn foo() {
|
|
|
|
a { b { c } d }
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![SpanLabel {
|
|
|
|
start: Position { string: "a", count: 1 },
|
|
|
|
end: Position { string: "d", count: 1 },
|
2017-01-20 20:57:21 -06:00
|
|
|
label: "",
|
2019-12-22 16:42:04 -06:00
|
|
|
}],
|
|
|
|
r#"
|
2017-01-20 20:57:21 -06:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:3
|
|
|
|
|
|
|
|
|
3 | a { b { c } d }
|
|
|
|
| ^^^^^^^^^^^^^
|
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-01-20 20:57:21 -06:00
|
|
|
}
|
2017-04-06 14:18:18 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_snippet() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-04-06 14:18:18 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
X1 Y1 Z1
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
X2 Y2 Z2
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "X1", count: 1 },
|
|
|
|
label: "`X` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Z1", count: 1 },
|
|
|
|
end: Position { string: "Z3", count: 1 },
|
|
|
|
label: "`Y` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-04-06 14:18:18 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:6
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______^
|
2017-04-06 14:18:18 -05:00
|
|
|
4 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |____^____-
|
2017-04-06 14:18:18 -05:00
|
|
|
| ||____|
|
2017-04-14 18:38:10 -05:00
|
|
|
| | `X` is a good letter
|
2017-04-06 14:18:18 -05:00
|
|
|
5 | | 1
|
|
|
|
6 | | 2
|
|
|
|
7 | | 3
|
|
|
|
... |
|
|
|
|
15 | | X2 Y2 Z2
|
|
|
|
16 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |___________- `Y` is a good letter too
|
2017-04-06 14:18:18 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-04-06 14:18:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_snippet_multiple_spans() {
|
2019-12-22 16:42:04 -06:00
|
|
|
test_harness(
|
|
|
|
r#"
|
2017-04-06 14:18:18 -05:00
|
|
|
fn foo() {
|
|
|
|
X0 Y0 Z0
|
|
|
|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
X1 Y1 Z1
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
X2 Y2 Z2
|
|
|
|
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
|
X3 Y3 Z3
|
|
|
|
}
|
|
|
|
"#,
|
2019-12-22 16:42:04 -06:00
|
|
|
vec![
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Y0", count: 1 },
|
|
|
|
end: Position { string: "Y3", count: 1 },
|
|
|
|
label: "`Y` is a good letter",
|
|
|
|
},
|
|
|
|
SpanLabel {
|
|
|
|
start: Position { string: "Z1", count: 1 },
|
|
|
|
end: Position { string: "Z2", count: 1 },
|
|
|
|
label: "`Z` is a good letter too",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
r#"
|
2017-04-06 14:18:18 -05:00
|
|
|
error: foo
|
|
|
|
--> test.rs:3:6
|
|
|
|
|
|
|
|
|
3 | X0 Y0 Z0
|
2017-04-14 18:38:10 -05:00
|
|
|
| ______^
|
2017-04-06 14:18:18 -05:00
|
|
|
4 | | 1
|
|
|
|
5 | | 2
|
|
|
|
6 | | 3
|
|
|
|
7 | | X1 Y1 Z1
|
2017-04-14 18:38:10 -05:00
|
|
|
| |_________-
|
2017-04-06 14:18:18 -05:00
|
|
|
8 | || 4
|
|
|
|
9 | || 5
|
|
|
|
10 | || 6
|
|
|
|
11 | || X2 Y2 Z2
|
2017-04-14 18:38:10 -05:00
|
|
|
| ||__________- `Z` is a good letter too
|
2017-04-06 14:18:18 -05:00
|
|
|
... |
|
|
|
|
15 | | 10
|
|
|
|
16 | | X3 Y3 Z3
|
2017-04-14 18:38:10 -05:00
|
|
|
| |_______^ `Y` is a good letter
|
2017-04-06 14:18:18 -05:00
|
|
|
|
2019-12-22 16:42:04 -06:00
|
|
|
"#,
|
|
|
|
);
|
2017-04-06 14:18:18 -05:00
|
|
|
}
|