Skip to content

Commit

Permalink
fix(raw): Stop swapping the text's order
Browse files Browse the repository at this point in the history
Fixes #79
  • Loading branch information
epage committed Dec 26, 2017
1 parent 89d7d20 commit bd45c14
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/tags/raw_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ pub fn raw_block(_tag_name: &str,
_options: &LiquidOptions)
-> Result<Box<Renderable>> {
let content = tokens.iter().fold("".to_owned(), |a, b| {
a +
match *b {
Element::Expression(_, ref text) |
Element::Tag(_, ref text) |
Element::Raw(ref text) => text,
}.to_owned() + &a
}
});
Ok(Box::new(RawT { content: content }))
}
Expand All @@ -36,6 +37,7 @@ pub fn raw_block(_tag_name: &str,
mod test {
use super::*;
use compiler;
use interpreter;

fn options() -> LiquidOptions {
let mut options = LiquidOptions::default();
Expand All @@ -45,7 +47,7 @@ mod test {
}

#[test]
fn test_raw() {
fn raw_text() {
let raw = raw_block("raw",
&[],
&vec![Element::Expression(vec![], "This is a test".to_owned())],
Expand All @@ -54,4 +56,32 @@ mod test {
let output = raw.render(&mut Default::default()).unwrap();
assert_eq!(output, Some("This is a test".to_owned()));
}

#[test]
fn raw_escaped() {
let text = "{%raw%}{%if%}{%endraw%}";

let tokens = compiler::tokenize(&text).unwrap();
let template = compiler::parse(&tokens, &options())
.map(interpreter::Template::new)
.unwrap();

let mut context = Context::new();
let output = template.render(&mut context).unwrap();
assert_eq!(output, Some("{%if%}".to_owned()));
}

#[test]
fn raw_mixed() {
let text = "{%raw%}hello{%if%}world{%endraw%}";

let tokens = compiler::tokenize(&text).unwrap();
let template = compiler::parse(&tokens, &options())
.map(interpreter::Template::new)
.unwrap();

let mut context = Context::new();
let output = template.render(&mut context).unwrap();
assert_eq!(output, Some("hello{%if%}world".to_owned()));
}
}

0 comments on commit bd45c14

Please sign in to comment.