Skip to content

Commit f460f83

Browse files
committed
Test and fix consecutive variable interpolations
1 parent f2964b0 commit f460f83

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/line/lex.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn lex(line: &str) -> Result<Vec<Token>> {
102102
};
103103
if !is_escaped && c == ESCAPE_CHAR {
104104
is_escaped = true;
105-
} else if !is_escaped && !in_interpolation && quote == '"' && c == INTERPOLATION_CHAR {
105+
} else if !is_escaped && quote == '"' && c == INTERPOLATION_CHAR {
106106
// Entering interpolation
107107
in_interpolation = true;
108108
current.as_mut().unwrap().push(Segment::empty_variable());
@@ -218,9 +218,11 @@ mod tests {
218218
fn interpolations() {
219219
assert_eq!(lex("$x").unwrap(), vec![string([lit(""), var("x")])]);
220220
assert_eq!(lex("test$x").unwrap(), vec![string([lit("test"), var("x")])]);
221+
assert_eq!(lex("test$x$y").unwrap(), vec![string([lit("test"), var("x"), var("y")])]);
221222
assert_eq!(lex("test $x").unwrap(), vec![lit_string(["test"]), string([lit(""), var("x")])]);
222223
assert_eq!(lex("'test$x'").unwrap(), vec![lit_string(["test$x"])]);
223224
assert_eq!(lex(r#""$abc""#).unwrap(), vec![string([lit(""), var("abc"), lit("")])]);
225+
assert_eq!(lex(r#""$abc$ghi""#).unwrap(), vec![string([lit(""), var("abc"), var("ghi"), lit("")])]);
224226
assert_eq!(lex(r#""test$x""#).unwrap(), vec![string([lit("test"), var("x"), lit("")])]);
225227
assert_eq!(lex(r#""$var_with_underscore abc""#).unwrap(), vec![string([lit(""), var("var_with_underscore"), lit(" abc")])]);
226228
assert_eq!(lex(r#""$var_with-hyphen""#).unwrap(), vec![string([lit(""), var("var_with"), lit("-hyphen")])]);

0 commit comments

Comments
 (0)