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