Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 24, 2024
1 parent b499842 commit ced5d7d
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 234 deletions.
45 changes: 25 additions & 20 deletions askama_derive/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,17 @@ mod tests {

#[test]
fn get_source() {
let path = Config::new("", None)
let path = Config::new("", None, None)
.and_then(|config| config.find_template("b.html", None))
.unwrap();
assert_eq!(get_template_source(&path).unwrap(), "bar");
assert_eq!(get_template_source(&path, None).unwrap(), "bar");
}

#[test]
fn test_default_config() {
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
root.push("templates");
let config = Config::new("", None).unwrap();
let config = Config::new("", None, None).unwrap();
assert_eq!(config.dirs, vec![root]);
}

Expand All @@ -387,7 +387,7 @@ mod tests {
fn test_config_dirs() {
let mut root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
root.push("tpl");
let config = Config::new("[general]\ndirs = [\"tpl\"]", None).unwrap();
let config = Config::new("[general]\ndirs = [\"tpl\"]", None, None).unwrap();
assert_eq!(config.dirs, vec![root]);
}

Expand All @@ -401,7 +401,7 @@ mod tests {

#[test]
fn find_absolute() {
let config = Config::new("", None).unwrap();
let config = Config::new("", None, None).unwrap();
let root = config.find_template("a.html", None).unwrap();
let path = config.find_template("sub/b.html", Some(&root)).unwrap();
assert_eq_rooted(&path, "sub/b.html");
Expand All @@ -410,22 +410,22 @@ mod tests {
#[test]
#[should_panic]
fn find_relative_nonexistent() {
let config = Config::new("", None).unwrap();
let config = Config::new("", None, None).unwrap();
let root = config.find_template("a.html", None).unwrap();
config.find_template("c.html", Some(&root)).unwrap();
}

#[test]
fn find_relative() {
let config = Config::new("", None).unwrap();
let config = Config::new("", None, None).unwrap();
let root = config.find_template("sub/b.html", None).unwrap();
let path = config.find_template("c.html", Some(&root)).unwrap();
assert_eq_rooted(&path, "sub/c.html");
}

#[test]
fn find_relative_sub() {
let config = Config::new("", None).unwrap();
let config = Config::new("", None, None).unwrap();
let root = config.find_template("sub/b.html", None).unwrap();
let path = config.find_template("sub1/d.html", Some(&root)).unwrap();
assert_eq_rooted(&path, "sub/sub1/d.html");
Expand All @@ -448,7 +448,7 @@ mod tests {
"#;

let default_syntax = Syntax::default();
let config = Config::new(raw_config, None).unwrap();
let config = Config::new(raw_config, None, None).unwrap();
assert_eq!(config.default_syntax, "foo");

let foo = config.syntaxes.get("foo").unwrap();
Expand Down Expand Up @@ -480,7 +480,7 @@ mod tests {
"#;

let default_syntax = Syntax::default();
let config = Config::new(raw_config, None).unwrap();
let config = Config::new(raw_config, None, None).unwrap();
assert_eq!(config.default_syntax, "foo");

let foo = config.syntaxes.get("foo").unwrap();
Expand Down Expand Up @@ -517,7 +517,7 @@ mod tests {
default_syntax = "emoji"
"#;

let config = Config::new(raw_config, None).unwrap();
let config = Config::new(raw_config, None, None).unwrap();
assert_eq!(config.default_syntax, "emoji");

let foo = config.syntaxes.get("emoji").unwrap();
Expand All @@ -537,7 +537,7 @@ mod tests {
name = "too_short"
block_start = "<"
"#;
let config = Config::new(raw_config, None);
let config = Config::new(raw_config, None, None);
assert_eq!(
config.unwrap_err().msg,
r#"delimiters must be at least two characters long: "<""#,
Expand All @@ -548,7 +548,7 @@ mod tests {
name = "contains_ws"
block_start = " {{ "
"#;
let config = Config::new(raw_config, None);
let config = Config::new(raw_config, None, None);
assert_eq!(
config.unwrap_err().msg,
r#"delimiters may not contain white spaces: " {{ ""#,
Expand All @@ -561,7 +561,7 @@ mod tests {
expr_start = "{{$"
comment_start = "{{#"
"#;
let config = Config::new(raw_config, None);
let config = Config::new(raw_config, None, None);
assert_eq!(
config.unwrap_err().msg,
r#"a delimiter may not be the prefix of another delimiter: "{{" vs "{{$""#,
Expand All @@ -576,7 +576,7 @@ mod tests {
syntax = [{ name = "default" }]
"#;

let _config = Config::new(raw_config, None).unwrap();
let _config = Config::new(raw_config, None, None).unwrap();
}

#[cfg(feature = "toml")]
Expand All @@ -588,7 +588,7 @@ mod tests {
{ name = "foo", block_start = "%%" } ]
"#;

let _config = Config::new(raw_config, None).unwrap();
let _config = Config::new(raw_config, None, None).unwrap();
}

#[cfg(feature = "toml")]
Expand All @@ -600,7 +600,7 @@ mod tests {
default_syntax = "foo"
"#;

let _config = Config::new(raw_config, None).unwrap();
let _config = Config::new(raw_config, None, None).unwrap();
}

#[cfg(feature = "config")]
Expand All @@ -613,6 +613,7 @@ mod tests {
extensions = ["js"]
"#,
None,
None,
)
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -641,11 +642,12 @@ mod tests {
whitespace = "suppress"
"#,
None,
None,
)
.unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Suppress);

let config = Config::new(r#""#, None).unwrap();
let config = Config::new(r#""#, None, None).unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Preserve);

let config = Config::new(
Expand All @@ -654,6 +656,7 @@ mod tests {
whitespace = "preserve"
"#,
None,
None,
)
.unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Preserve);
Expand All @@ -664,6 +667,7 @@ mod tests {
whitespace = "minimize"
"#,
None,
None,
)
.unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Minimize);
Expand All @@ -681,17 +685,18 @@ mod tests {
whitespace = "suppress"
"#,
Some(&"minimize".to_owned()),
None,
)
.unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Minimize);

let config = Config::new(r#""#, Some(&"minimize".to_owned())).unwrap();
let config = Config::new(r#""#, Some(&"minimize".to_owned()), None).unwrap();
assert_eq!(config.whitespace, WhitespaceHandling::Minimize);
}

#[test]
fn test_config_whitespace_error() {
let config = Config::new(r#""#, Some("trim"));
let config = Config::new(r#""#, None, Some("trim"));
if let Err(err) = config {
assert_eq!(err.msg, "invalid value for `whitespace`: \"trim\"");
} else {
Expand Down
Loading

0 comments on commit ced5d7d

Please sign in to comment.