test: simplify filter tests
This commit is contained in:
parent
46fa250c49
commit
6c2ef0deae
|
@ -353,37 +353,33 @@ cfg_json! {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn assert_render<T: Render>(expr: &T, expected: &str) {
|
||||||
|
let mut buf = Buffer::new();
|
||||||
|
Render::render(expr, &mut buf).unwrap();
|
||||||
|
assert_eq!(buf.as_str(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assert_render_escaped<T: Render>(expr: &T, expected: &str) {
|
||||||
|
let mut buf = Buffer::new();
|
||||||
|
Render::render_escaped(expr, &mut buf).unwrap();
|
||||||
|
assert_eq!(buf.as_str(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn case() {
|
fn case() {
|
||||||
let mut buf = Buffer::new();
|
assert_render(&upper("hElLo, WOrLd!"), "HELLO, WORLD!");
|
||||||
upper(&"hElLO, WOrLd!").render(&mut buf).unwrap();
|
assert_render(&lower("hElLo, WOrLd!"), "hello, world!");
|
||||||
assert_eq!(buf.as_str(), "HELLO, WORLD!");
|
assert_render_escaped(&lower("<h1>TITLE</h1>"), "<h1>title</h1>");
|
||||||
|
|
||||||
buf.clear();
|
|
||||||
lower(&"hElLO, WOrLd!").render(&mut buf).unwrap();
|
|
||||||
assert_eq!(buf.as_str(), "hello, world!");
|
|
||||||
|
|
||||||
buf.clear();
|
|
||||||
lower(&"<h1>TITLE</h1>").render_escaped(&mut buf).unwrap();
|
|
||||||
assert_eq!(buf.as_str(), "<h1>title</h1>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trim_test() {
|
fn trim_test() {
|
||||||
let mut buf = Buffer::new();
|
assert_render(&trim(""), "");
|
||||||
trim(&" hello ").render(&mut buf).unwrap();
|
assert_render(&trim("\n \t\r\x0C"), "");
|
||||||
trim(&"hello ").render(&mut buf).unwrap();
|
|
||||||
trim(&" hello").render(&mut buf).unwrap();
|
|
||||||
assert_eq!(buf.as_str(), "hellohellohello");
|
|
||||||
|
|
||||||
let mut buf = Buffer::new();
|
assert_render(&trim("hello world!"), "hello world!");
|
||||||
trim(&"hello ").render(&mut buf).unwrap();
|
assert_render(&trim("hello world!\n"), "hello world!");
|
||||||
trim(&" hello").render(&mut buf).unwrap();
|
assert_render(&trim("\thello world!"), "hello world!");
|
||||||
trim(&"hello").render(&mut buf).unwrap();
|
assert_render(&trim("\thello world!\r\n"), "hello world!");
|
||||||
assert_eq!(buf.as_str(), "hellohellohello");
|
|
||||||
|
|
||||||
let mut buf = Buffer::new();
|
|
||||||
trim(&" hello").render(&mut buf).unwrap();
|
|
||||||
assert_eq!(buf.as_str(), "hello");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue