From 16a22e76fa77af3f6ec3fbfa11304b7cb84bd4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Caillaut?= Date: Tue, 31 Mar 2020 02:15:44 +0200 Subject: [PATCH] Fail if a language is set both in config.default_languages and config.languages --- components/config/src/config.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/components/config/src/config.rs b/components/config/src/config.rs index 210f60ef..c0b43c92 100644 --- a/components/config/src/config.rs +++ b/components/config/src/config.rs @@ -215,6 +215,10 @@ impl Config { 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()); if !config.ignored_content.is_empty() { @@ -657,4 +661,19 @@ anchors = "off" assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Safe); 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)); + } }