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(); let theme = Theme::parse(theme_str).unwrap();
// We expect an error here // We expect an error here
assert!(!config.add_theme_extra(&theme).is_ok()); assert!(config.add_theme_extra(&theme).is_err());
} }
#[test] #[test]
@ -714,7 +714,7 @@ highlight_theme = "asdf"
"#; "#;
let config = Config::parse(config); let config = Config::parse(config);
assert_eq!(config.is_err(), true); assert!(config.is_err());
} }
#[test] #[test]
@ -728,7 +728,7 @@ highlight_themes_css = [
"#; "#;
let config = Config::parse(config); let config = Config::parse(config);
assert_eq!(config.is_err(), true); assert!(config.is_err());
} }
// https://github.com/getzola/zola/issues/1687 // 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("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap(); File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file( let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts")); 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("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap(); File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file( let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts")); 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("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap(); File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file( let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts")); 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("graph.jpg")).unwrap();
File::create(nested_path.join("fail.png")).unwrap(); File::create(nested_path.join("fail.png")).unwrap();
let res = Page::from_file( let res = Page::from_file(nested_path.join("index.md").as_path(), &Config::default(), path);
nested_path.join("index.md").as_path(),
&Config::default(),
&path.to_path_buf(),
);
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();
assert_eq!(page.file.parent, path.join("content").join("posts")); assert_eq!(page.file.parent, path.join("content").join("posts"));
@ -682,8 +666,7 @@ And here's another. [^2]
let mut config = Config::default(); let mut config = Config::default();
config.ignored_content_globset = Some(gsb.build().unwrap()); config.ignored_content_globset = Some(gsb.build().unwrap());
let res = let res = Page::from_file(nested_path.join("index.md").as_path(), &config, path);
Page::from_file(nested_path.join("index.md").as_path(), &config, &path.to_path_buf());
assert!(res.is_ok()); assert!(res.is_ok());
let page = res.unwrap(); let page = res.unwrap();

View File

@ -75,7 +75,7 @@ mod tests {
let page1 = create_page_with_date("2018-01-01", None); let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", None); let page2 = create_page_with_date("2017-01-01", None);
let page3 = create_page_with_date("2019-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[0], page3.file.path);
assert_eq!(pages[1], page1.file.path); assert_eq!(pages[1], page1.file.path);
assert_eq!(pages[2], page2.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 page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_date("2017-01-01", Some("2022-02-01")); let page2 = create_page_with_date("2017-01-01", Some("2022-02-01"));
let page3 = create_page_with_date("2019-01-01", None); 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[0], page2.file.path);
assert_eq!(pages[1], page3.file.path); assert_eq!(pages[1], page3.file.path);
assert_eq!(pages[2], page1.file.path); assert_eq!(pages[2], page1.file.path);
@ -99,7 +99,7 @@ mod tests {
let page1 = create_page_with_weight(2); let page1 = create_page_with_weight(2);
let page2 = create_page_with_weight(3); let page2 = create_page_with_weight(3);
let page3 = create_page_with_weight(1); 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 // Should be sorted by weight
assert_eq!(pages[0], page3.file.path); assert_eq!(pages[0], page3.file.path);
assert_eq!(pages[1], page1.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 pages: Vec<Page> = titles.iter().map(|title| create_page_with_title(title)).collect();
let (sorted_pages, ignored_pages) = 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 // Should be sorted by title in lexical order
let sorted_titles: Vec<_> = sorted_pages let sorted_titles: Vec<_> = sorted_pages
.iter() .iter()
@ -153,7 +153,7 @@ mod tests {
fn can_find_ignored_pages() { fn can_find_ignored_pages() {
let page1 = create_page_with_date("2018-01-01", None); let page1 = create_page_with_date("2018-01-01", None);
let page2 = create_page_with_weight(1); 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!(pages[0], page1.file.path);
assert_eq!(ignored_pages.len(), 1); assert_eq!(ignored_pages.len(), 1);
assert_eq!(ignored_pages[0], page2.file.path); 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); let assets = find_related_assets(path, &Config::default(), true);
assert_eq!(assets.len(), 5); assert_eq!(assets.len(), 5);
assert_eq!( assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 5);
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
5
);
for asset in for asset in ["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"] {
vec!["example.js", "graph.jpg", "fail.png", "subdir/example.js", "extensionless"] assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
{
assert!(assets
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
} }
} }
@ -112,16 +104,10 @@ mod tests {
File::create(path.join("subdir").join("example.js")).unwrap(); File::create(path.join("subdir").join("example.js")).unwrap();
let assets = find_related_assets(path, &Config::default(), false); let assets = find_related_assets(path, &Config::default(), false);
assert_eq!(assets.len(), 4); assert_eq!(assets.len(), 4);
assert_eq!( assert_eq!(assets.iter().filter(|p| p.extension().unwrap_or_default() != "md").count(), 4);
assets.iter().filter(|p| p.extension().unwrap_or("".as_ref()) != "md").count(),
4
);
for asset in vec!["example.js", "graph.jpg", "fail.png", "extensionless"] { for asset in ["example.js", "graph.jpg", "fail.png", "extensionless"] {
assert!(assets assert!(assets.iter().any(|p| p.strip_prefix(path).unwrap() == Path::new(asset)))
.iter()
.find(|p| p.strip_prefix(path).unwrap() == Path::new(asset))
.is_some())
} }
} }
#[test] #[test]

View File

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

View File

@ -178,8 +178,8 @@ mod tests {
#[test] #[test]
fn template_fallback_is_successful() { fn template_fallback_is_successful() {
let mut tera = Tera::parse("test-templates/*.html").unwrap(); 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/index.html", "Hello").unwrap();
tera.add_raw_template(&"hyde/templates/theme-only.html", "Hello").unwrap(); tera.add_raw_template("hyde/templates/theme-only.html", "Hello").unwrap();
// Check finding existing template // Check finding existing template
assert_eq!(check_template_fallbacks("index.html", &tera, &None), Some("index.html")); 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) { fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
let root_dir = dir let root_dir = dir
.ancestors() .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")); .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 // if we got here we found root_dir so config file should exist so we can unwrap safely