v2 / vlib / v / tests / builtin_strings_and_interpolation / cstrings_test.c.v
13 lines · 12 sloc · 338 bytes · c5e8ad19dfd6b57396b7781d423195305ce8c6b4
Raw
1fn test_cstring() {
2 w := &char(c'world')
3 hlen := unsafe { C.strlen(c'hello') }
4 wlen := unsafe { C.strlen(w) }
5 assert hlen == 5
6 assert wlen == 5
7}
8
9fn test_cstring_with_zeros() {
10 rawbytes := &char(c'\x00username\x00password')
11 s := unsafe { rawbytes.vstring_with_len(18) }
12 assert s.hex() == '00757365726e616d650070617373776f7264'
13}
14