@@ -890,4 +890,60 @@ func Test_float_compare()
890890 call v9.CheckLegacyAndVim9Success (lines )
891891endfunc
892892
893+ func Test_string_interp ()
894+ let lines = << trim END
895+ call assert_equal (' ' , $ " " )
896+ call assert_equal (' foobar' , $ " foobar" )
897+ #" Escaping rules.
898+ call assert_equal (' "foo"{bar}' , $ " \" foo\" {{bar}}" )
899+ call assert_equal (' "foo"{bar}' , $ ' "foo"{{bar}}' )
900+ call assert_equal (' foobar' , $ " {\" foo\" }" .. $ ' {'' bar'' }' )
901+ #" Whitespace before/after the expression.
902+ call assert_equal (' 3' , $ " { 1 + 2 }" )
903+ #" String conversion.
904+ call assert_equal (' hello from ' .. v: version , $ " hello from {v:version}" )
905+ call assert_equal (' hello from ' .. v: version , $ ' hello from {v:version}' )
906+ #" Paper over a small difference between VimScript behaviour.
907+ call assert_equal (string (v: true ), $ " {v:true}" )
908+ call assert_equal (' (1+1=2)' , $ " (1+1={1 + 1})" )
909+ #" Hex-escaped opening brace: char2nr('{') == 0x7b
910+ call assert_equal (' esc123ape' , $ " esc\x7b 123}ape" )
911+ call assert_equal (' me{}me' , $ " me{\x7b }\x7d me" )
912+ VAR var1 = " sun"
913+ VAR var2 = " shine"
914+ call assert_equal (' sunshine' , $ " {var1}{var2}" )
915+ call assert_equal (' sunsunsun' , $ " {var1->repeat(3)}" )
916+ #" Multibyte strings.
917+ call assert_equal (' say ハロー・ワールド' , $ " say {'ハロー・ワールド'}" )
918+ #" Nested.
919+ call assert_equal (' foobarbaz' , $ " foo{$\" {'bar'}\" }baz" )
920+ #" Do not evaluate blocks when the expr is skipped.
921+ VAR tmp = 0
922+ if v: false
923+ echo " ${ LET tmp += 1 }"
924+ endif
925+ call assert_equal (0 , tmp)
926+
927+ #" Stray closing brace.
928+ call assert_fails (' echo $"moo}"' , ' E1278:' )
929+ #" Undefined variable in expansion.
930+ call assert_fails (' echo $"{moo}"' , ' E121:' )
931+ #" Empty blocks are rejected.
932+ call assert_fails (' echo $"{}"' , ' E15:' )
933+ call assert_fails (' echo $"{ }"' , ' E15:' )
934+ END
935+ call v9.CheckLegacyAndVim9Success (lines )
936+
937+ let lines = << trim END
938+ call assert_equal (' 5' , $ " {({x -> x + 1})(4)}" )
939+ END
940+ call v9.CheckLegacySuccess (lines )
941+
942+ let lines = << trim END
943+ call assert_equal (' 5' , $ " {((x) => x + 1)(4)}" )
944+ call assert_fails (' echo $"{ # foo }"' , ' E1279:' )
945+ END
946+ call v9.CheckDefAndScriptSuccess (lines )
947+ endfunc
948+
893949" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments