v / vlib / flag / cmd_exe_style_flags_test.v
65 lines · 58 sloc · 2.02 KB · ddb6685d8a0cb498b5031c644f16d05ac3121ced
Raw
1// Test .short (POSIX) parse style
2import flag
3
4const cmd_exe_args = ['/a', 'C:\\', '/B', 'xyz', '/a', 'D:\\', '/d', '/e', '/c', '"xyz"']
5
6const cmd_exe_mixed_args = ['/a', 'C:\\', '/Big', 'hij', '/a', 'D:\\', '/Dev', '/e', '/c', '"xyz"']
7
8const cmd_exe_args_with_tail = ['/a', 'C:\\', '/b', '/B', 'xyz', '/a', 'D:\\', '/d', '/e', '/c',
9 '"xyz"', '"/path/to/x"', '"/path/to/y"', '"/path/to/z"']
10
11struct Config {
12 big_b string = 'def' @[long: Big; short: B]
13 small_b bool @[short: b]
14 a_device []string @[short: a]
15 paths []string @[tail]
16 not_mapped string = 'not changed'
17 e bool
18 b bool @[long: Dev; only: d]
19 u string @[short: c]
20}
21
22fn test_cmd_exe() {
23 config, _ := flag.to_struct[Config](cmd_exe_args, style: .cmd_exe, delimiter: '/')!
24 assert config.big_b == 'xyz'
25 assert config.small_b == false
26 assert config.a_device.len == 2
27 assert config.a_device[0] == 'C:\\'
28 assert config.a_device[1] == 'D:\\'
29 assert config.paths.len == 0
30 assert config.not_mapped == 'not changed'
31 assert config.e
32 assert config.b
33 assert config.u == '"xyz"'
34}
35
36fn test_cmd_exe_mixed() {
37 config, _ := flag.to_struct[Config](cmd_exe_mixed_args, style: .cmd_exe, delimiter: '/')!
38 assert config.big_b == 'hij'
39 assert config.small_b == false
40 assert config.a_device.len == 2
41 assert config.a_device[0] == 'C:\\'
42 assert config.a_device[1] == 'D:\\'
43 assert config.paths.len == 0
44 assert config.not_mapped == 'not changed'
45 assert config.e
46 assert config.b
47 assert config.u == '"xyz"'
48}
49
50fn test_cmd_exe_with_tail() {
51 config, _ := flag.to_struct[Config](cmd_exe_args_with_tail, style: .cmd_exe, delimiter: '/')!
52 assert config.big_b == 'xyz'
53 assert config.small_b
54 assert config.a_device.len == 2
55 assert config.a_device[0] == 'C:\\'
56 assert config.a_device[1] == 'D:\\'
57 assert config.paths.len == 3
58 assert config.paths[0] == '"/path/to/x"'
59 assert config.paths[1] == '"/path/to/y"'
60 assert config.paths[2] == '"/path/to/z"'
61 assert config.not_mapped == 'not changed'
62 assert config.e
63 assert config.b
64 assert config.u == '"xyz"'
65}
66