Merge pull request #981 from GaaH/fail-if-lang-set-twice

Fail if a language is set both in config.default_languages and config…
This commit is contained in:
Vincent Prouillet 2020-03-31 09:04:23 +02:00 committed by GitHub
commit ff6238afdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -215,6 +215,10 @@ impl Config {
bail!("Highlight theme {} not available", config.highlight_theme) bail!("Highlight theme {} not available", config.highlight_theme)
} }
if config.languages.iter().any(|l| l.code == config.default_language) {
bail!("Default language `{}` should not appear both in `config.default_language` and `config.languages`", config.default_language)
}
config.build_timestamp = Some(Utc::now().timestamp()); config.build_timestamp = Some(Utc::now().timestamp());
if !config.ignored_content.is_empty() { if !config.ignored_content.is_empty() {
@ -657,4 +661,19 @@ anchors = "off"
assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Safe); assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Safe);
assert_eq!(config.slugify.anchors, SlugifyStrategy::Off); assert_eq!(config.slugify.anchors, SlugifyStrategy::Off);
} }
#[test]
fn error_on_language_set_twice() {
let config_str = r#"
base_url = "https://remplace-par-ton-url.fr"
default_language = "fr"
languages = [
{ code = "fr" },
{ code = "en" },
]
"#;
let config = Config::parse(config_str);
let err = config.unwrap_err();
assert_eq!("Default language `fr` should not appear both in `config.default_language` and `config.languages`", format!("{}", err));
}
} }