v2 / vlib / v / tests / options / option_unwrap_none_test.v
19 lines · 17 sloc · 389 bytes · 9c4dfd3848089a2a003a2391ea4a78367c941d0f
Raw
1fn fake_prompt[T](msg string, default ?T) string {
2 return build_prompt(msg, default)
3}
4
5fn build_prompt[T](msg string, default ?T) string {
6 mut s := msg
7 if default != none {
8 s += ' [${default}]'
9 }
10 s += ': '
11 return s
12}
13
14fn test_main() {
15 p1 := fake_prompt[string]('hello', none)
16 p2 := fake_prompt[string]('hello', 'world')
17 assert p1 == 'hello: '
18 assert p2 == 'hello [world]: '
19}
20