v2 / vlib / v / fmt / tests / to_string_2_forms_keep.vv
33 lines · 31 sloc · 591 bytes · 017ace6ea7402430a992aa0820d5e472ebca74c7
Raw
1fn abc() string {
2 unsafe {
3 mut fullpath := vcalloc(4)
4 fullpath[0] = `a`
5 fullpath[1] = `b`
6 fullpath[2] = `c`
7 fullpath[3] = 0
8 return fullpath.vstring()
9 }
10 return ''
11}
12
13fn def() string {
14 unsafe {
15 mut fullpath := vcalloc(4)
16 fullpath[0] = `a`
17 fullpath[1] = `b`
18 fullpath[2] = `c`
19 fullpath[3] = 0
20 return fullpath.vstring_with_len(3)
21 }
22 return ''
23}
24
25fn main() {
26 assert 'abc' == abc()
27 assert 'abc' == def()
28 abc_str1 := ptr_str(abc().str)
29 abc_str2 := ptr_str(abc().str)
30 println('abc_str1: ${abc_str1}')
31 println('abc_str2: ${abc_str2}')
32 assert abc_str1 != abc_str2
33}
34