v / vlib / v2 / tests / string_interpolation.v
20 lines · 18 sloc · 954 bytes · 7519f915ffdafd3229fdd8912f7d78481614cb35
Raw
1module main
2
3fn test_main() {
4 string_literal_raw_a := r'raw string Literal b'
5 string_literal_inter_a := 'a == abc${a:2f} && and b == abc${b}...'
6 string_literal_inter_b := '${@MOD}.${@METHOD} - ${fn_call(unsafe { 1 })}'
7 string_literal_inter_c := '${mod.fn_call(1)} | ${mod.fn_call('a').join(' ')} > out'
8 // NOTE: d) tests nested quotes of same kind (although why is this allowed?)
9 string_literal_inter_d := '${mod.fn_call(1)} | ${mod.fn_call(unsafe { 1 }, mod.fn_call('a')).join(' ')} > out'
10 string_literal_inter_e := '${mod.fn_call(1)} | ${mod.fn_call(mod.fn_call('a')).join(' ')} > out'
11 // TODO: remember to talk to alex to confirm behaviour of nested strings
12 // x := 'hello ${foo('${x}')} ${x}'
13}
14
15fn test_basic() {
16 pi := 3.14159265359
17 pi_name := 'Pi'
18 pi_symbol := `π`
19 pi_description := '${pi_name} (${pi_symbol}) is a mathematical constant that is the ratio of a circle\'s circumference to its diameter, approximately equal ${pi:.5}.'
20}
21