scanner: fix interpolation with more embedded string args (#7258)

pull/7274/head
yuyi 2020-12-12 01:15:59 +08:00 committed by GitHub
parent 9c1a5c5117
commit 2a731e1c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -1005,7 +1005,7 @@ fn (mut s Scanner) ident_string() string {
is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r`
is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1] == `c`
if is_quote {
if s.is_inside_string {
if s.is_inside_string || s.is_enclosed_inter || s.is_inter_start {
s.inter_quote = q
} else {
s.quote = q

View File

@ -2,6 +2,10 @@ fn show_info(a string) string {
return a
}
fn show_more_info(a string, b string) string {
return a + b
}
fn test_interpolation_string_args() {
assert '${show_info("abc")}' == 'abc'
assert '${show_info('abc')}' == 'abc'
@ -11,4 +15,17 @@ fn test_interpolation_string_args() {
assert '${"aaa"}' == 'aaa'
assert '${'aaa'}' == 'aaa'
assert '${"aaa" + "bbb"}' == 'aaabbb'
assert '${'aaa' + 'bbb'}' == 'aaabbb'
assert '${"aaa" + 'bbb'}' == 'aaabbb'
assert '${'aaa' + "bbb"}' == 'aaabbb'
assert '${show_more_info("aaa", "bbb")}' == 'aaabbb'
assert '${show_more_info('aaa', 'bbb')}' == 'aaabbb'
assert '${show_more_info("aaa", 'bbb')}' == 'aaabbb'
assert '${show_more_info('aaa', "bbb")}' == 'aaabbb'
assert '1_${show_more_info("aaa", "111")} 2_${show_more_info("bbb", "222")}' == '1_aaa111 2_bbb222'
assert '1_${show_more_info('aaa', '111')} 2_${show_more_info('bbb', '222')}' == '1_aaa111 2_bbb222'
}