Skip to content

Commit

Permalink
Rollup merge of #69095 - GuillaumeGomez:minified-theme-check, r=Dylan…
Browse files Browse the repository at this point in the history
…-DPC

Minified theme check

Fixes #69071.

r? @kinnison
  • Loading branch information
Dylan-DPC committed Feb 12, 2020
2 parents e86019c + 109260f commit 839adda
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/librustdoc/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,23 @@ fn get_previous_positions(events: &[Events], mut pos: usize) -> Vec<usize> {
}

fn build_rule(v: &[u8], positions: &[usize]) -> String {
positions
.chunks(2)
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
.collect::<String>()
.trim()
.replace("\n", " ")
.replace("/", "")
.replace("\t", " ")
.replace("{", "")
.replace("}", "")
.split(' ')
.filter(|s| s.len() > 0)
.collect::<Vec<&str>>()
.join(" ")
minifier::css::minify(
&positions
.chunks(2)
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
.collect::<String>()
.trim()
.replace("\n", " ")
.replace("/", "")
.replace("\t", " ")
.replace("{", "")
.replace("}", "")
.split(' ')
.filter(|s| s.len() > 0)
.collect::<Vec<&str>>()
.join(" "),
)
.unwrap_or_else(|_| String::new())
}

fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> FxHashSet<CssPath> {
Expand Down
13 changes: 13 additions & 0 deletions src/librustdoc/theme/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@ fn check_invalid_css() {
let events = load_css_events(b"*");
assert_eq!(events.len(), 0);
}

#[test]
fn test_with_minification() {
let text = include_str!("../html/static/themes/dark.css");
let minified = minifier::css::minify(&text).expect("CSS minification failed");

let against = load_css_paths(text.as_bytes());
let other = load_css_paths(minified.as_bytes());

let mut ret = Vec::new();
get_differences(&against, &other, &mut ret);
assert!(ret.is_empty());
}

0 comments on commit 839adda

Please sign in to comment.