Skip to content

Commit

Permalink
Improve theme checker by removing unneeded conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 20, 2019
1 parent 165a95b commit 640bdbd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/librustdoc/theme.rs
Expand Up @@ -103,7 +103,7 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool {
if let Some(&Events::StartComment(_)) = events.last() {
return false;
}
pos + 1 < v.len() && v[pos + 1] == b'/'
v[pos + 1] == b'/'
}

fn load_css_events(v: &[u8]) -> Vec<Events> {
Expand All @@ -112,7 +112,7 @@ fn load_css_events(v: &[u8]) -> Vec<Events> {

while pos + 1 < v.len() {
match v[pos] {
b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => {
b'/' if v[pos + 1] == b'*' => {
events.push(Events::StartComment(pos));
pos += 1;
}
Expand All @@ -123,7 +123,7 @@ fn load_css_events(v: &[u8]) -> Vec<Events> {
b'\n' if previous_is_line_comment(&events) => {
events.push(Events::EndComment(pos));
}
b'*' if pos + 1 < v.len() && v[pos + 1] == b'/' => {
b'*' if v[pos + 1] == b'/' => {
events.push(Events::EndComment(pos + 2));
pos += 1;
}
Expand Down Expand Up @@ -264,9 +264,11 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>)
}
}

pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath, diag: &Handler)
-> (bool, Vec<String>)
{
pub fn test_theme_against<P: AsRef<Path>>(
f: &P,
against: &CssPath,
diag: &Handler,
) -> (bool, Vec<String>) {
let data = try_something!(fs::read(f), diag, (false, vec![]));
let paths = load_css_paths(&data);
let mut ret = vec![];
Expand Down Expand Up @@ -372,4 +374,10 @@ a {
let events = load_css_events(&[]);
assert_eq!(events.len(), 0);
}

#[test]
fn check_invalid_css() {
let events = load_css_events(b"*");
assert_eq!(events.len(), 0);
}
}

0 comments on commit 640bdbd

Please sign in to comment.