Skip to content

Commit 6cba069

Browse files
author
Keith Hall
committed
switch syntax tests back to a normal Vec instead of a VecDeque
1 parent f485533 commit 6cba069

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/syntax_tests.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub enum SyntaxTestFileResult {
2222
Success(usize),
2323
}
2424

25-
use std::collections::VecDeque;
2625
use highlighting::ScopeSelectors;
2726

2827
#[derive(Debug)]
@@ -35,8 +34,8 @@ struct SyntaxTestAssertionRange {
3534
scope_selector_text: String,
3635
}
3736

38-
fn get_syntax_test_assertions(token_start: &str, token_end: Option<&str>, text: &str) -> VecDeque<SyntaxTestAssertionRange> {
39-
let mut assertions = VecDeque::new();
37+
fn get_syntax_test_assertions(token_start: &str, token_end: Option<&str>, text: &str) -> Vec<SyntaxTestAssertionRange> {
38+
let mut assertions = Vec::new();
4039
let mut test_line_offset = 0;
4140
let mut test_line_len = 0;
4241
let mut line_number = 0;
@@ -89,10 +88,10 @@ fn get_syntax_test_assertions(token_start: &str, token_end: Option<&str>, text:
8988
scope_selector_text: assertion.scope_selector_text.clone(),
9089
};
9190
assertion.end_char = test_line_len;
92-
assertions.push_back(assertion);
93-
assertions.push_back(remainder);
91+
assertions.push(assertion);
92+
assertions.push(remainder);
9493
} else {
95-
assertions.push_back(assertion);
94+
assertions.push(assertion);
9695
}
9796

9897
line_has_assertions = true;
@@ -147,7 +146,7 @@ pub/*(crate)*/ fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text
147146
results
148147
}
149148

150-
let mut assertions = get_syntax_test_assertions(testtoken_start, testtoken_end, &text);
149+
let assertions = get_syntax_test_assertions(testtoken_start, testtoken_end, &text);
151150
//println!("{:?}", assertions);
152151

153152
// iterate over the lines of the file, testing them
@@ -158,6 +157,7 @@ pub/*(crate)*/ fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text
158157
let mut scopes_on_line_being_tested = Vec::new();
159158
let mut line_number = 0;
160159
let mut relevant_assertions = Vec::new();
160+
let mut assertion_index = 0;
161161

162162
let mut assertion_failures: usize = 0;
163163
let mut total_assertions: usize = 0;
@@ -172,12 +172,13 @@ pub/*(crate)*/ fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text
172172
let ops = state.parse_line(&line);
173173
// find all the assertions that relate to the current line
174174
relevant_assertions.clear();
175-
while let Some(assertion) = assertions.pop_front() {
175+
while assertion_index < assertions.len() {
176+
let assertion = &assertions[assertion_index];
176177
let pos = assertion.test_line_offset + assertion.begin_char;
177178
if pos >= offset && pos < eol_offset {
178179
relevant_assertions.push(assertion);
180+
assertion_index += 1;
179181
} else {
180-
assertions.push_front(assertion);
181182
break;
182183
}
183184
}
@@ -245,7 +246,7 @@ pub/*(crate)*/ fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text
245246

246247
// no point continuing to parse the file if there are no syntax test assertions left
247248
// (unless we want to prove that no panics etc. occur while parsing the rest of the file ofc...)
248-
if assertions.is_empty() || (assertion_failures > 0 && out_opts.failfast) {
249+
if assertion_index == assertions.len() || (assertion_failures > 0 && out_opts.failfast) {
249250
// NOTE: the total counts only really show how many assertions were checked when failing fast
250251
// - they are not accurate total counts
251252
break;

0 commit comments

Comments
 (0)