aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-06 14:43:06 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-06 14:44:35 +0200
commit0514e4fec7e996cfbe4b97e5d09b6eebaf14eb43 (patch)
tree9f457b28f7f64f0f5dfd05639a35006dec0a77fe /askama_derive
parent670dbe4aecf4280ef254cafa7d97d1890946b3e5 (diff)
downloadaskama-0514e4fec7e996cfbe4b97e5d09b6eebaf14eb43.tar.gz
askama-0514e4fec7e996cfbe4b97e5d09b6eebaf14eb43.tar.bz2
askama-0514e4fec7e996cfbe4b97e5d09b6eebaf14eb43.zip
Add tests for find_template_from_path()
Diffstat (limited to '')
-rw-r--r--askama_derive/src/path.rs30
-rw-r--r--askama_derive/templates/a.html1
-rw-r--r--askama_derive/templates/sub/b.html1
-rw-r--r--askama_derive/templates/sub/c.html1
-rw-r--r--askama_derive/templates/sub/sub1/d.html1
5 files changed, 34 insertions, 0 deletions
diff --git a/askama_derive/src/path.rs b/askama_derive/src/path.rs
index 728c7ec..9431306 100644
--- a/askama_derive/src/path.rs
+++ b/askama_derive/src/path.rs
@@ -48,3 +48,33 @@ pub fn get_template_source(tpl_file: &str) -> String {
f.read_to_string(&mut s).unwrap();
s
}
+
+#[cfg(test)]
+mod tests {
+ use super::find_template_from_path;
+ use super::Path;
+
+ #[test]
+ fn find_absolute() {
+ let path = find_template_from_path("sub/b.html", Some("a.html"));
+ assert_eq!(path, Path::new("sub/b.html"));
+ }
+
+ #[test]
+ #[should_panic]
+ fn find_relative_nonexistent() {
+ find_template_from_path("b.html", Some("a.html"));
+ }
+
+ #[test]
+ fn find_relative() {
+ let path = find_template_from_path("c.html", Some("sub/b.html"));
+ assert_eq!(path, Path::new("sub/c.html"));
+ }
+
+ #[test]
+ fn find_relative_sub() {
+ let path = find_template_from_path("sub1/d.html", Some("sub/b.html"));
+ assert_eq!(path, Path::new("sub/sub1/d.html"));
+ }
+}
diff --git a/askama_derive/templates/a.html b/askama_derive/templates/a.html
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/askama_derive/templates/a.html
@@ -0,0 +1 @@
+foo
diff --git a/askama_derive/templates/sub/b.html b/askama_derive/templates/sub/b.html
new file mode 100644
index 0000000..5716ca5
--- /dev/null
+++ b/askama_derive/templates/sub/b.html
@@ -0,0 +1 @@
+bar
diff --git a/askama_derive/templates/sub/c.html b/askama_derive/templates/sub/c.html
new file mode 100644
index 0000000..7601807
--- /dev/null
+++ b/askama_derive/templates/sub/c.html
@@ -0,0 +1 @@
+baz
diff --git a/askama_derive/templates/sub/sub1/d.html b/askama_derive/templates/sub/sub1/d.html
new file mode 100644
index 0000000..fa11a6a
--- /dev/null
+++ b/askama_derive/templates/sub/sub1/d.html
@@ -0,0 +1 @@
+echo