Skip to content

Commit

Permalink
Allow expr and block tags to be multiline
Browse files Browse the repository at this point in the history
This is particularly useful now that we have list and map literals.
  • Loading branch information
rossmacarthur committed Jan 17, 2025
1 parent b4f5aff commit 62302a0
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/compile/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl Token {
}

fn is_whitespace(c: char) -> bool {
matches!(c, '\t' | ' ')
matches!(c, '\t' | ' ' | '\r' | '\n')
}

#[cfg(feature = "unicode")]
Expand Down Expand Up @@ -720,6 +720,23 @@ mod tests {
);
}

#[test]
fn lex_expr_multiline() {
let tokens = lex("lorem {{\n ipsum }} dolor").unwrap();
assert_eq!(
tokens,
[
(Token::Raw, "lorem "),
(Token::BeginExpr, "{{"),
(Token::Whitespace, "\n "),
(Token::Ident, "ipsum"),
(Token::Whitespace, " "),
(Token::EndExpr, "}}"),
(Token::Raw, " dolor")
]
);
}

#[test]
fn lex_expr_literals() {
let tokens = lex("lorem {{ [1, 3] {.} }} dolor").unwrap();
Expand Down Expand Up @@ -862,6 +879,23 @@ mod tests {
);
}

#[test]
fn lex_block_multiline() {
let tokens = lex("lorem {%\n ipsum %} dolor").unwrap();
assert_eq!(
tokens,
[
(Token::Raw, "lorem "),
(Token::BeginBlock, "{%"),
(Token::Whitespace, "\n "),
(Token::Ident, "ipsum"),
(Token::Whitespace, " "),
(Token::EndBlock, "%}"),
(Token::Raw, " dolor")
]
);
}

#[test]
fn lex_block_and_expr() {
let tokens =
Expand Down

0 comments on commit 62302a0

Please sign in to comment.