1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix string array initialization with interpolation

This commit is contained in:
Uwe Krüger 2020-06-13 22:38:10 +02:00 committed by GitHub
parent 0115c5e76c
commit 50cd0ed785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -1166,7 +1166,7 @@ fn (mut p Parser) string_expr() ast.Expr {
vals << p.tok.lit
p.next()
if p.tok.kind != .str_dollar {
continue
break
}
p.next()
exprs << p.expr(0)

View File

@ -83,3 +83,22 @@ fn test_array_of_map_interpolation() {
a << {'c': int(3), 'd': 4}
assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]"
}
fn test_array_initialization_with_interpolation() {
sysroot := '/usr'
a := [
'abcd'
'$sysroot/xyz'
'u$sysroot/vw'
'/rr$sysroot'
'lmno'
]
assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']"
b := [
'a${sysroot:5}/r'
'ert'
]
assert '$b' == "['a /usr/r', 'ert']"
c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<']
assert '$c' == "['xy', 'r/usr', '/usr/t', '>/usr<']"
}