Fix tests + rustfmt
This commit is contained in:
parent
d19855e909
commit
b96b187eca
|
@ -125,6 +125,7 @@ mod tests {
|
|||
check_page_for_anchor, check_url, has_anchor, is_valid, message, LinkChecker, LINKS,
|
||||
};
|
||||
use mockito::mock;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
// NOTE: HTTP mock paths below are randomly generated to avoid name
|
||||
// collisions. Mocks with the same path can sometimes bleed between tests
|
||||
|
@ -189,9 +190,8 @@ mod tests {
|
|||
|
||||
let url = format!("{}{}", mockito::server_url(), "/C4Szbfnvj6M0LoPk");
|
||||
let res = check_url(&url, &LinkChecker::default());
|
||||
assert!(res.is_valid());
|
||||
assert!(res.code.is_some());
|
||||
assert!(res.error.is_none());
|
||||
assert!(is_valid(&res));
|
||||
assert_eq!(res.unwrap(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -46,7 +46,8 @@ fn bench_render_feed(b: &mut test::Bencher) {
|
|||
None,
|
||||
&site.config.default_language,
|
||||
None,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -55,11 +55,7 @@ struct SerializedTaxonomyItem<'a> {
|
|||
|
||||
impl<'a> SerializedTaxonomyItem<'a> {
|
||||
pub fn from_item(item: &'a TaxonomyItem) -> Self {
|
||||
SerializedTaxonomyItem {
|
||||
name: &item.name,
|
||||
slug: &item.slug,
|
||||
permalink: &item.permalink,
|
||||
}
|
||||
SerializedTaxonomyItem { name: &item.name, slug: &item.slug, permalink: &item.permalink }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,10 +642,8 @@ impl Site {
|
|||
/// Inject live reload script tag if in live reload mode
|
||||
fn inject_livereload(&self, mut html: String) -> String {
|
||||
if let Some(port) = self.live_reload {
|
||||
let script = format!(
|
||||
r#"<script src="/livereload.js?port={}&mindelay=10"></script>"#,
|
||||
port,
|
||||
);
|
||||
let script =
|
||||
format!(r#"<script src="/livereload.js?port={}&mindelay=10"></script>"#, port,);
|
||||
if let Some(index) = html.rfind("</body>") {
|
||||
html.insert_str(index, &script);
|
||||
} else {
|
||||
|
@ -775,12 +769,7 @@ impl Site {
|
|||
} else {
|
||||
library.pages_values()
|
||||
};
|
||||
self.render_feed(
|
||||
pages,
|
||||
None,
|
||||
&self.config.default_language,
|
||||
None,
|
||||
)?;
|
||||
self.render_feed(pages, None, &self.config.default_language, None)?;
|
||||
}
|
||||
|
||||
for lang in &self.config.languages {
|
||||
|
@ -789,12 +778,7 @@ impl Site {
|
|||
}
|
||||
let pages =
|
||||
library.pages_values().iter().filter(|p| p.lang == lang.code).cloned().collect();
|
||||
self.render_feed(
|
||||
pages,
|
||||
Some(&PathBuf::from(lang.code.clone())),
|
||||
&lang.code,
|
||||
None,
|
||||
)?;
|
||||
self.render_feed(pages, Some(&PathBuf::from(lang.code.clone())), &lang.code, None)?;
|
||||
}
|
||||
|
||||
self.render_404()?;
|
||||
|
@ -1104,11 +1088,12 @@ impl Site {
|
|||
|
||||
context.insert(
|
||||
"last_updated",
|
||||
pages.iter()
|
||||
pages
|
||||
.iter()
|
||||
.filter_map(|page| page.meta.updated.as_ref())
|
||||
.chain(pages[0].meta.date.as_ref())
|
||||
.max() // I love lexicographically sorted date strings
|
||||
.unwrap(), // Guaranteed because of pages[0].meta.date
|
||||
.max() // I love lexicographically sorted date strings
|
||||
.unwrap(), // Guaranteed because of pages[0].meta.date
|
||||
);
|
||||
let library = self.library.read().unwrap();
|
||||
// limit to the last n elements if the limit is set; otherwise use all.
|
||||
|
@ -1125,12 +1110,8 @@ impl Site {
|
|||
|
||||
let feed_filename = &self.config.feed_filename;
|
||||
let feed_url = if let Some(ref base) = base_path {
|
||||
self.config.make_permalink(
|
||||
&base
|
||||
.join(feed_filename)
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/"),
|
||||
)
|
||||
self.config
|
||||
.make_permalink(&base.join(feed_filename).to_string_lossy().replace('\\', "/"))
|
||||
} else {
|
||||
self.config.make_permalink(feed_filename)
|
||||
};
|
||||
|
|
|
@ -119,11 +119,19 @@ fn can_build_multilingual_site() {
|
|||
assert!(file_exists!(public, "atom.xml"));
|
||||
assert!(file_contains!(public, "atom.xml", "https://example.com/blog/something-else/"));
|
||||
assert!(!file_contains!(public, "atom.xml", "https://example.com/fr/blog/something-else/"));
|
||||
assert!(file_contains!(public, "atom.xml", r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">"#));
|
||||
assert!(file_contains!(
|
||||
public,
|
||||
"atom.xml",
|
||||
r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">"#
|
||||
));
|
||||
assert!(file_exists!(public, "fr/atom.xml"));
|
||||
assert!(!file_contains!(public, "fr/atom.xml", "https://example.com/blog/something-else/"));
|
||||
assert!(file_contains!(public, "fr/atom.xml", "https://example.com/fr/blog/something-else/"));
|
||||
assert!(file_contains!(public, "fr/atom.xml", r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">"#));
|
||||
assert!(file_contains!(
|
||||
public,
|
||||
"fr/atom.xml",
|
||||
r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">"#
|
||||
));
|
||||
// Italian doesn't have feed enabled
|
||||
assert!(!file_exists!(public, "it/atom.xml"));
|
||||
|
||||
|
@ -134,8 +142,16 @@ fn can_build_multilingual_site() {
|
|||
assert!(!file_contains!(public, "authors/index.html", "Vincent"));
|
||||
assert!(!file_exists!(public, "auteurs/index.html"));
|
||||
assert!(file_exists!(public, "authors/queen-elizabeth/atom.xml"));
|
||||
assert!(file_contains!(public, "authors/queen-elizabeth/atom.xml", r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">"#));
|
||||
assert!(file_contains!(public, "authors/queen-elizabeth/atom.xml", r#"<title> - Queen Elizabeth</title>"#));
|
||||
assert!(file_contains!(
|
||||
public,
|
||||
"authors/queen-elizabeth/atom.xml",
|
||||
r#"<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">"#
|
||||
));
|
||||
assert!(file_contains!(
|
||||
public,
|
||||
"authors/queen-elizabeth/atom.xml",
|
||||
r#"<title> - Queen Elizabeth</title>"#
|
||||
));
|
||||
|
||||
assert!(file_exists!(public, "tags/index.html"));
|
||||
assert!(file_contains!(public, "tags/index.html", "hello"));
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated>
|
||||
<link href="{{ page.permalink | safe }}" type="text/html"/>
|
||||
<id>{{ page.permalink | safe }}</id>
|
||||
<content type="html">{{ page.content }}</description>
|
||||
</item>
|
||||
<content type="html">{{ page.content }}</content>
|
||||
</entry>
|
||||
{%- endfor %}
|
||||
</feed>
|
||||
|
|
|
@ -60,7 +60,9 @@ fn make_path_with_lang(path: String, lang: &str, config: &Config) -> Result<Stri
|
|||
}
|
||||
|
||||
if !config.languages.iter().any(|x| x.code == lang) {
|
||||
return Err(format!("`{}` is not an authorized language (check config.languages).", lang).into());
|
||||
return Err(
|
||||
format!("`{}` is not an authorized language (check config.languages).", lang).into()
|
||||
);
|
||||
}
|
||||
|
||||
let mut splitted_path: Vec<String> = path.split(".").map(String::from).collect();
|
||||
|
@ -90,13 +92,14 @@ impl TeraFn for GetUrl {
|
|||
if path.starts_with("@/") {
|
||||
let path_with_lang = match make_path_with_lang(path, &lang, &self.config) {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(e)
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
match resolve_internal_link(&path_with_lang, &self.permalinks) {
|
||||
Ok(resolved) => Ok(to_value(resolved.permalink).unwrap()),
|
||||
Err(_) => {
|
||||
Err(format!("Could not resolve URL for link `{}` not found.", path_with_lang).into())
|
||||
Err(format!("Could not resolve URL for link `{}` not found.", path_with_lang)
|
||||
.into())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -599,7 +602,10 @@ title = "A title"
|
|||
args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap());
|
||||
args.insert("lang".to_string(), to_value("it").unwrap());
|
||||
let err = static_fn.call(&args).unwrap_err();
|
||||
assert_eq!("`it` is not an authorized language (check config.languages).", format!("{}", err));
|
||||
assert_eq!(
|
||||
"`it` is not an authorized language (check config.languages).",
|
||||
format!("{}", err)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -608,17 +614,20 @@ title = "A title"
|
|||
let mut permalinks = HashMap::new();
|
||||
permalinks.insert(
|
||||
"a_section/a_page.md".to_string(),
|
||||
"https://remplace-par-ton-url.fr/a_section/a_page/".to_string()
|
||||
"https://remplace-par-ton-url.fr/a_section/a_page/".to_string(),
|
||||
);
|
||||
permalinks.insert(
|
||||
"a_section/a_page.en.md".to_string(),
|
||||
"https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string()
|
||||
"https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string(),
|
||||
);
|
||||
let static_fn = GetUrl::new(config, permalinks);
|
||||
let mut args = HashMap::new();
|
||||
args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap());
|
||||
args.insert("lang".to_string(), to_value("fr").unwrap());
|
||||
assert_eq!(static_fn.call(&args).unwrap(), "https://remplace-par-ton-url.fr/a_section/a_page/");
|
||||
assert_eq!(
|
||||
static_fn.call(&args).unwrap(),
|
||||
"https://remplace-par-ton-url.fr/a_section/a_page/"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -627,16 +636,19 @@ title = "A title"
|
|||
let mut permalinks = HashMap::new();
|
||||
permalinks.insert(
|
||||
"a_section/a_page.md".to_string(),
|
||||
"https://remplace-par-ton-url.fr/a_section/a_page/".to_string()
|
||||
"https://remplace-par-ton-url.fr/a_section/a_page/".to_string(),
|
||||
);
|
||||
permalinks.insert(
|
||||
"a_section/a_page.en.md".to_string(),
|
||||
"https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string()
|
||||
"https://remplace-par-ton-url.fr/en/a_section/a_page/".to_string(),
|
||||
);
|
||||
let static_fn = GetUrl::new(config, permalinks);
|
||||
let mut args = HashMap::new();
|
||||
args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap());
|
||||
args.insert("lang".to_string(), to_value("en").unwrap());
|
||||
assert_eq!(static_fn.call(&args).unwrap(), "https://remplace-par-ton-url.fr/en/a_section/a_page/");
|
||||
assert_eq!(
|
||||
static_fn.call(&args).unwrap(),
|
||||
"https://remplace-par-ton-url.fr/en/a_section/a_page/"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue