Skip to content

Commit 18bb754

Browse files
authored
Rollup merge of rust-lang#61181 - GuillaumeGomez:fix-theme-checker, r=kinnison
Fix theme-checker failure Fixes rust-lang#61145. I didn't find a way to check it without strongly depending on the output... Is there a way to check if a program fails without checking its output? r? @QuietMisdreavus
2 parents 3a8536e + 640bdbd commit 18bb754

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/librustdoc/theme.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool {
103103
if let Some(&Events::StartComment(_)) = events.last() {
104104
return false;
105105
}
106-
pos + 1 < v.len() && v[pos + 1] == b'/'
106+
v[pos + 1] == b'/'
107107
}
108108

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

113-
while pos < v.len() - 1 {
113+
while pos + 1 < v.len() {
114114
match v[pos] {
115-
b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => {
115+
b'/' if v[pos + 1] == b'*' => {
116116
events.push(Events::StartComment(pos));
117117
pos += 1;
118118
}
@@ -123,7 +123,7 @@ fn load_css_events(v: &[u8]) -> Vec<Events> {
123123
b'\n' if previous_is_line_comment(&events) => {
124124
events.push(Events::EndComment(pos));
125125
}
126-
b'*' if pos + 1 < v.len() && v[pos + 1] == b'/' => {
126+
b'*' if v[pos + 1] == b'/' => {
127127
events.push(Events::EndComment(pos + 2));
128128
pos += 1;
129129
}
@@ -264,9 +264,11 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>)
264264
}
265265
}
266266

267-
pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath, diag: &Handler)
268-
-> (bool, Vec<String>)
269-
{
267+
pub fn test_theme_against<P: AsRef<Path>>(
268+
f: &P,
269+
against: &CssPath,
270+
diag: &Handler,
271+
) -> (bool, Vec<String>) {
270272
let data = try_something!(fs::read(f), diag, (false, vec![]));
271273
let paths = load_css_paths(&data);
272274
let mut ret = vec![];
@@ -366,4 +368,16 @@ a {
366368
get_differences(&other, &against, &mut ret);
367369
assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]);
368370
}
371+
372+
#[test]
373+
fn check_empty_css() {
374+
let events = load_css_events(&[]);
375+
assert_eq!(events.len(), 0);
376+
}
377+
378+
#[test]
379+
fn check_invalid_css() {
380+
let events = load_css_events(b"*");
381+
assert_eq!(events.len(), 0);
382+
}
369383
}

0 commit comments

Comments
 (0)