Skip to content

Commit

Permalink
trim scope selector at test token end
Browse files Browse the repository at this point in the history
i.e. allow text after the assertion to not interfere with the assertion. This is how ST works when it executes the syntax tests.
  • Loading branch information
keith-hall committed Mar 13, 2017
1 parent 3e95235 commit cb5353e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions examples/syntest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ fn get_line_assertion_details<'a>(testtoken_start: &str, testtoken_end: Option<&
let (before_token_start, token_and_rest_of_line) = line.split_at(index);

if let Some(captures) = SYNTAX_TEST_ASSERTION_PATTERN.captures(&token_and_rest_of_line[testtoken_start.len()..]) {
let mut sst = captures.get(3).unwrap().as_str().trim_right(); // get the scope selector text
let mut sst = captures.get(3).unwrap().as_str(); // get the scope selector text
let mut only_whitespace_after_token_end = true;

if let Some(token) = testtoken_end { // if there is an end token defined in the test file header
sst = sst.trim_right_matches(&token); // trim it from the scope selector text
if let Some(end_token_pos) = sst.find(token) { // and there is an end token in the line
let (ss, after_token_end) = sst.split_at(end_token_pos); // the scope selector text ends at the end token
sst = &ss;
only_whitespace_after_token_end = after_token_end.trim_right().is_empty();
}
}
return Some(AssertionRange {
begin_char: index + if captures.get(2).is_some() { testtoken_start.len() + captures.get(2).unwrap().start() } else { 0 },
end_char: index + if captures.get(2).is_some() { testtoken_start.len() + captures.get(2).unwrap().end() } else { 1 },
scope_selector_text: sst,
is_pure_assertion_line: before_token_start.trim_left().is_empty(), // if only whitespace precedes the test token on the line, then it is a pure assertion line
})
is_pure_assertion_line: before_token_start.trim_left().is_empty() && only_whitespace_after_token_end, // if only whitespace surrounds the test tokens on the line, then it is a pure assertion line
});
}
}
None
Expand Down

0 comments on commit cb5353e

Please sign in to comment.