diff options
author | Veetaha <[email protected]> | 2020-02-06 00:33:18 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-17 20:24:33 +0000 |
commit | 9fdf984958901a6bf16772c2c88b3163f044b390 (patch) | |
tree | b3f86c533c6a9a86a9183cb117e23efd382c045e /crates/ra_syntax/src/tests.rs | |
parent | 9053003e3b298b38f6029b860efc5baed1996385 (diff) |
ra_syntax: reshape SyntaxError for the sake of removing redundancy
Diffstat (limited to 'crates/ra_syntax/src/tests.rs')
-rw-r--r-- | crates/ra_syntax/src/tests.rs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs index fb22b9e54..2533d0c44 100644 --- a/crates/ra_syntax/src/tests.rs +++ b/crates/ra_syntax/src/tests.rs | |||
@@ -5,7 +5,7 @@ use std::{ | |||
5 | 5 | ||
6 | use test_utils::{collect_tests, dir_tests, project_dir, read_text}; | 6 | use test_utils::{collect_tests, dir_tests, project_dir, read_text}; |
7 | 7 | ||
8 | use crate::{fuzz, tokenize, Location, SourceFile, SyntaxError, TextRange, Token}; | 8 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, Token}; |
9 | 9 | ||
10 | #[test] | 10 | #[test] |
11 | fn lexer_tests() { | 11 | fn lexer_tests() { |
@@ -128,25 +128,14 @@ fn dump_tokens_and_errors(tokens: &[Token], errors: &[SyntaxError], text: &str) | |||
128 | writeln!(acc, "{:?} {} {:?}", token.kind, token_len, token_text).unwrap(); | 128 | writeln!(acc, "{:?} {} {:?}", token.kind, token_len, token_text).unwrap(); |
129 | } | 129 | } |
130 | for err in errors { | 130 | for err in errors { |
131 | let err_range = location_to_range(err.location()); | ||
132 | writeln!( | 131 | writeln!( |
133 | acc, | 132 | acc, |
134 | "> error{:?} token({:?}) msg({})", | 133 | "> error{:?} token({:?}) msg({})", |
135 | err.location(), | 134 | err.range(), |
136 | &text[err_range], | 135 | &text[*err.range()], |
137 | err.kind() | 136 | err.message() |
138 | ) | 137 | ) |
139 | .unwrap(); | 138 | .unwrap(); |
140 | } | 139 | } |
141 | return acc; | 140 | acc |
142 | |||
143 | // FIXME: copy-pasted this from `ra_ide/src/diagnostics.rs` | ||
144 | // `Location` will be refactored soon in new PR, see todos here: | ||
145 | // https://github.com/rust-analyzer/rust-analyzer/issues/223 | ||
146 | fn location_to_range(location: Location) -> TextRange { | ||
147 | match location { | ||
148 | Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), | ||
149 | Location::Range(range) => range, | ||
150 | } | ||
151 | } | ||
152 | } | 141 | } |