v / vlib / flag / flag_parse_test.v
40 lines · 33 sloc · 1.22 KB · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1import flag
2
3pub struct Options {
4pub:
5 verbosity int
6 dump_usage bool
7pub mut:
8 additional_args []string
9 archs []string
10 v_flags []string
11 api_level string
12}
13
14fn test_flag_parse() {
15 args := ['/my/app', '-v', '3', '-f', '-d sdl_memory_no_gc', '-f', '-d shy_use_wren', '--api',
16 '21', '--archs', 'arm64-v8a', '/path/to/input.v']
17
18 mut fp := flag.new_flag_parser(args)
19 fp.application('bug')
20 fp.version('0.2.0')
21 fp.description('bugged')
22 fp.arguments_description('not important')
23
24 fp.skip_executable()
25
26 mut opt := Options{
27 v_flags: fp.string_multi('flag', `f`, 'Additional flags for the V compiler')
28 archs: fp.string('archs', 0, 'arm64-v8a,armeabi-v7a,x86,x86_64',
29 'Comma separated string with any of archs').split(',')
30 dump_usage: fp.bool('help', `h`, false, 'Show this help message and exit')
31 verbosity: fp.int_opt('verbosity', `v`, 'Verbosity level 1-3') or { 0 }
32 api_level: fp.string('api', 0, '21', 'Android API level to use (--list-apis)')
33 }
34
35 opt.additional_args = fp.finalize() or { panic(err) }
36
37 assert opt.v_flags[0] == '-d sdl_memory_no_gc'
38 assert opt.v_flags[1] == '-d shy_use_wren' // looks like the builtin support for `-h` eats the "h" in this flag
39 assert opt.dump_usage == false
40}
41