Fix clippy lint warnings (#1888)

This commit is contained in:
bemyak 2022-06-04 21:29:33 +03:00 committed by GitHub
parent e9e6cadc6c
commit 6989eb73ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 58 deletions

View file

@ -677,7 +677,7 @@ bar = "baz"
"#;
let theme = Theme::parse(theme_str).unwrap();
// We expect an error here
assert!(!config.add_theme_extra(&theme).is_ok());
assert!(config.add_theme_extra(&theme).is_err());
}
#[test]
@ -714,7 +714,7 @@ highlight_theme = "asdf"
"#;
let config = Config::parse(config);
assert_eq!(config.is_err(), true);
assert!(config.is_err());
}
#[test]
@ -728,7 +728,7 @@ highlight_themes_css = [
"#;
let config = Config::parse(config);
assert_eq!(config.is_err(), true);
assert!(config.is_err());
}
// https://github.com/getzola/zola/issues/1687

View file

@ -563,11 +563,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
@ -591,11 +587,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
@ -619,11 +611,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
@ -649,11 +637,7 @@ And here's another. [^2]
File::create(nested_path.join("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file(
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
assert!(res.is_ok());
let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts"));
@ -682,8 +666,7 @@ And here's another. [^2]
let mut config = Config::default();
config.ignored_content_globset = Some(gsb.build().unwrap());
let res =
Page::from_file(nested_path.join("index.md").as_path(), &config, &path.to_path_buf());
let res = Page::from_file(nested_path.join("index.md").as_path(), &config, path);
assert!(res.is_ok());
let page = res.unwrap();

View file

@ -75,7 +75,7 @@ mod tests {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", None);
let page3 = create_page_with_date("2019-01-01", None);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::Date);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::Date);
assert_eq!(pages[0], page3.file.path);
assert_eq!(pages[1], page1.file.path);
assert_eq!(pages[2], page2.file.path);
@ -87,7 +87,7 @@ mod tests {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", Some("2022-02-01"));
let page3 = create_page_with_date("2019-01-01", None);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::UpdateDate);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::UpdateDate);
assert_eq!(pages[0], page2.file.path);
assert_eq!(pages[1], page3.file.path);
assert_eq!(pages[2], page1.file.path);
@ -99,7 +99,7 @@ mod tests {
let page1 = create_page_with_weight(2);
let page2 = create_page_with_weight(3);
let page3 = create_page_with_weight(1);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2, &page3], SortBy::Weight);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2, &page3], SortBy::Weight);
// Should be sorted by weight
assert_eq!(pages[0], page3.file.path);
assert_eq!(pages[1], page1.file.path);
@ -123,7 +123,7 @@ mod tests {
];
let pages: Vec<Page> = titles.iter().map(|title| create_page_with_title(title)).collect();
let (sorted_pages, ignored_pages) =
sort_pages(&pages.iter().map(|p| p).collect::<Vec<_>>(), SortBy::Title);
sort_pages(&pages.iter().collect::<Vec<_>>(), SortBy::Title);
// Should be sorted by title in lexical order
let sorted_titles: Vec<_> = sorted_pages
.iter()
@ -153,7 +153,7 @@ mod tests {
fn can_find_ignored_pages() {
let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_weight(1);
let (pages, ignored_pages) = sort_pages(&vec![&page1, &page2], SortBy::Date);
let (pages, ignored_pages) = sort_pages(&[&page1, &page2], SortBy::Date);
assert_eq!(pages[0], page1.file.path);
assert_eq!(ignored_pages.len(), 1);
assert_eq!(ignored_pages[0], page2.file.path);

View file

@ -83,18 +83,10 @@ mod tests {
let assets = find_related_assets(path, &Config::default(), true);
assert_eq!(assets.len(), 5);
assert_eq!(
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
5
);
assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 5);
for asset in
vec!["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"]
{
assert!(assets
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
for asset in ["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"] {
assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
}
}
@ -112,16 +104,10 @@ mod tests {
File::create(path.join("subdir").join("example.js")).unwrap();
let assets = find_related_assets(path, &Config::default(), false);
assert_eq!(assets.len(), 4);
assert_eq!(
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
4
);
assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 4);
for asset in vec!["example.js", "graph.jpg", "fail.png", "extensionless"] {
assert!(assets
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
for asset in ["example.js", "graph.jpg", "fail.png", "extensionless"] {
assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
}
}
#[test]

View file

@ -186,7 +186,7 @@ mod tests {
let src_file_path = src_dir.path().join("test.txt");
let dest_file_path = dest_dir.path().join(src_file_path.strip_prefix(&base_path).unwrap());
File::create(&src_file_path).unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(
metadata(&src_file_path).and_then(|m| m.modified()).unwrap(),
@ -207,7 +207,7 @@ mod tests {
let mut src_file = File::create(&src_file_path).unwrap();
src_file.write_all(b"file1").unwrap();
}
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
{
let mut dest_file = File::create(&dest_file_path).unwrap();
dest_file.write_all(b"file2").unwrap();
@ -217,14 +217,14 @@ mod tests {
filetime::set_file_mtime(&src_file_path, filetime::FileTime::from_unix_time(0, 0)).unwrap();
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(0, 0))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file2");
// Copy occurs if the timestamps are different while the filesizes are same.
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(42, 42))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file1");
@ -235,7 +235,7 @@ mod tests {
}
filetime::set_file_mtime(&dest_file_path, filetime::FileTime::from_unix_time(0, 0))
.unwrap();
copy_file(&src_file_path, &dest_dir.path().to_path_buf(), &base_path, false).unwrap();
copy_file(&src_file_path, dest_dir.path(), &base_path, false).unwrap();
assert_eq!(read_to_string(&src_file_path).unwrap(), "file1");
assert_eq!(read_to_string(&dest_file_path).unwrap(), "file1");
}

View file

@ -178,8 +178,8 @@ mod tests {
#[test]
fn template_fallback_is_successful() {
let mut tera = Tera::parse("test-templates/*.html").unwrap();
tera.add_raw_template(&"hyde/templates/index.html", "Hello").unwrap();
tera.add_raw_template(&"hyde/templates/theme-only.html", "Hello").unwrap();
tera.add_raw_template("hyde/templates/index.html", "Hello").unwrap();
tera.add_raw_template("hyde/templates/theme-only.html", "Hello").unwrap();
// Check finding existing template
assert_eq!(check_template_fallbacks("index.html", &tera, &None), Some("index.html"));

View file

@ -15,7 +15,7 @@ mod prompt;
fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
let root_dir = dir
.ancestors()
.find_map(|a| if a.join(&config_path).exists() { Some(a) } else { None })
.find(|a| a.join(&config_path).exists())
.unwrap_or_else(|| panic!("could not find directory containing config file"));
// if we got here we found root_dir so config file should exist so we can unwrap safely