v2 / vlib / v / tests / generics / generics_str_intp_test.v
27 lines · 21 sloc · 399 bytes · 48dc7216e4de4bb8fe856a5028c26b677dbc63a0
Raw
1module main
2
3import strings
4
5pub struct MyStruct[T] {
6pub mut:
7 result T
8}
9
10pub fn (it MyStruct[T]) indent_str[T]() string {
11 mut res := strings.new_builder(32)
12 res.write_string('${it.result}')
13 return res.str()
14}
15
16fn test_generics_str_intp() {
17 x := MyStruct[int]{
18 result: 100
19 }
20
21 y := MyStruct[string]{
22 result: 'hello'
23 }
24
25 assert x.indent_str() == '100'
26 assert y.indent_str() == 'hello'
27}
28