aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar vallentin <mail@vallentin.dev>2021-03-10 08:52:36 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-03-10 13:09:56 +0100
commit606c68dd34d3ffd33e53c7d85ba2051ce24d5e1c (patch)
tree0a4522d0790d6038919be7cffee0079d54f0741b
parent8566d8258a960fc1456d271b25428cbd312ba42b (diff)
downloadaskama-606c68dd34d3ffd33e53c7d85ba2051ce24d5e1c.tar.gz
askama-606c68dd34d3ffd33e53c7d85ba2051ce24d5e1c.tar.bz2
askama-606c68dd34d3ffd33e53c7d85ba2051ce24d5e1c.zip
Added extension tests
Diffstat (limited to '')
-rw-r--r--askama_shared/src/input.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs
index febd51c..a0704aa 100644
--- a/askama_shared/src/input.rs
+++ b/askama_shared/src/input.rs
@@ -245,3 +245,51 @@ impl FromStr for Print {
})
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_ext() {
+ assert_eq!(extension(Path::new("foo-bar.txt")), Some("txt"));
+ assert_eq!(extension(Path::new("foo-bar.html")), Some("html"));
+ assert_eq!(extension(Path::new("foo-bar.unknown")), Some("unknown"));
+
+ assert_eq!(extension(Path::new("foo/bar/baz.txt")), Some("txt"));
+ assert_eq!(extension(Path::new("foo/bar/baz.html")), Some("html"));
+ assert_eq!(extension(Path::new("foo/bar/baz.unknown")), Some("unknown"));
+ }
+
+ #[test]
+ fn test_double_ext() {
+ assert_eq!(extension(Path::new("foo-bar.html.txt")), Some("txt"));
+ assert_eq!(extension(Path::new("foo-bar.txt.html")), Some("html"));
+ assert_eq!(extension(Path::new("foo-bar.txt.unknown")), Some("unknown"));
+
+ assert_eq!(extension(Path::new("foo/bar/baz.html.txt")), Some("txt"));
+ assert_eq!(extension(Path::new("foo/bar/baz.txt.html")), Some("html"));
+ assert_eq!(
+ extension(Path::new("foo/bar/baz.txt.unknown")),
+ Some("unknown")
+ );
+ }
+
+ #[test]
+ fn test_skip_jinja_ext() {
+ assert_eq!(extension(Path::new("foo-bar.html.j2")), Some("html"));
+ assert_eq!(extension(Path::new("foo-bar.html.jinja")), Some("html"));
+ assert_eq!(extension(Path::new("foo-bar.html.jinja2")), Some("html"));
+
+ assert_eq!(extension(Path::new("foo/bar/baz.txt.j2")), Some("txt"));
+ assert_eq!(extension(Path::new("foo/bar/baz.txt.jinja")), Some("txt"));
+ assert_eq!(extension(Path::new("foo/bar/baz.txt.jinja2")), Some("txt"));
+ }
+
+ #[test]
+ fn test_only_jinja_ext() {
+ assert_eq!(extension(Path::new("foo-bar.j2")), Some("j2"));
+ assert_eq!(extension(Path::new("foo-bar.jinja")), Some("jinja"));
+ assert_eq!(extension(Path::new("foo-bar.jinja2")), Some("jinja2"));
+ }
+}