aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 10:59:57 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-08 10:59:57 +0100
commitbba3950c37d4fa32ccf18ed1b093ecf48aec419d (patch)
tree8bda1944a5c9e724e85cd12466974f28ca54c3e2
parent4805acc8eb03541cb00ec39b4f20da49c51c9317 (diff)
downloadaskama-bba3950c37d4fa32ccf18ed1b093ecf48aec419d.tar.gz
askama-bba3950c37d4fa32ccf18ed1b093ecf48aec419d.tar.bz2
askama-bba3950c37d4fa32ccf18ed1b093ecf48aec419d.zip
Add unit tests for whitespace splitter
Diffstat (limited to '')
-rw-r--r--askama/src/parser.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/askama/src/parser.rs b/askama/src/parser.rs
index f338456..bb59b48 100644
--- a/askama/src/parser.rs
+++ b/askama/src/parser.rs
@@ -186,3 +186,26 @@ pub fn parse(src: &str) -> Vec<Node> {
IResult::Incomplete(_) => panic!("parsing incomplete"),
}
}
+
+#[cfg(test)]
+mod tests {
+ fn check_ws_split(s: &str, res: &(&[u8], &[u8], &[u8])) {
+ let node = super::split_ws_parts(s.as_bytes());
+ match node {
+ super::Node::Lit(lws, s, rws) => {
+ assert_eq!(lws, res.0);
+ assert_eq!(s, res.1);
+ assert_eq!(rws, res.2);
+ },
+ _ => { panic!("fail"); },
+ }
+ }
+ #[test]
+ fn test_ws_splitter() {
+ check_ws_split("a", &(b"", b"a", b""));
+ check_ws_split("", &(b"", b"", b""));
+ check_ws_split("\ta", &(b"\t", b"a", b""));
+ check_ws_split("b\n", &(b"", b"b", b"\n"));
+ check_ws_split(" \t\r\n", &(b" \t\r\n", b"", b""));
+ }
+}