v / vlib / flag / flag_to_tail_bool_test.v
80 lines · 70 sloc · 1.31 KB · ce88c56446fb5581f83135e55be9bfea46a850e1
Raw
1import flag
2
3struct CliOptions {
4 show_help bool @[long: 'help'; short: h]
5}
6
7struct CliOptions2 {
8 show_help bool @[long: 'help'; short: h]
9 long string
10}
11
12fn test_v_style_short_tail_bool() {
13 cli_options, unmatched := flag.to_struct[CliOptions](['some.exe', '-h'],
14 skip: 1
15 style: .v
16 mode: .relaxed
17 )!
18
19 if unmatched.len > 0 {
20 assert false
21 }
22 if cli_options.show_help {
23 assert true
24 } else {
25 assert false
26 }
27}
28
29fn test_v_style_long_tail_bool() {
30 cli_options, unmatched := flag.to_struct[CliOptions](['some.exe', '-help'],
31 skip: 1
32 style: .v
33 mode: .relaxed
34 )!
35
36 if unmatched.len > 0 {
37 assert false
38 }
39 if cli_options.show_help {
40 assert true
41 } else {
42 assert false
43 }
44}
45
46fn test_v_style_short_bool() {
47 cli_options, unmatched := flag.to_struct[CliOptions2](['some.exe', '-h', '-long', 'val'],
48 skip: 1
49 style: .v
50 mode: .relaxed
51 )!
52
53 if unmatched.len > 0 {
54 assert false
55 }
56 if cli_options.show_help {
57 assert true
58 } else {
59 assert false
60 }
61 assert cli_options.long == 'val'
62}
63
64fn test_v_style_long_bool() {
65 cli_options, unmatched := flag.to_struct[CliOptions2](['some.exe', '-help', '-long', 'val'],
66 skip: 1
67 style: .v
68 mode: .relaxed
69 )!
70
71 if unmatched.len > 0 {
72 assert false
73 }
74 if cli_options.show_help {
75 assert true
76 } else {
77 assert false
78 }
79 assert cli_options.long == 'val'
80}
81