v2 / vlib / v / tests / enums / enum_from_generic_static_call_test.v
23 lines · 20 sloc · 250 bytes · 0d6e386d09a073f31a570726a368a2158f2a8163
Raw
1fn prompt_enum[T](s string) !T {
2 if x := T.from(s) {
3 return x
4 }
5 return error('fail')
6}
7
8enum EnumA {
9 a
10 b
11 c
12}
13
14enum EnumB {
15 x
16 y
17 z
18}
19
20fn test_main() {
21 assert prompt_enum[EnumA]('a')! == EnumA.a
22 assert prompt_enum[EnumB]('x')! == EnumB.x
23}
24