Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix theme-checker failure #61181

Merged
merged 3 commits into from
Jun 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/librustdoc/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ 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'/'
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
}

fn load_css_events(v: &[u8]) -> Vec<Events> {
let mut pos = 0;
let mut events = Vec::with_capacity(100);

while pos < v.len() - 1 {
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>) {
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
let data = try_something!(fs::read(f), diag, (false, vec![]));
let paths = load_css_paths(&data);
let mut ret = vec![];
Expand Down Expand Up @@ -366,4 +368,16 @@ a {
get_differences(&other, &against, &mut ret);
assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]);
}

#[test]
fn check_empty_css() {
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);
}
}