| 1 | import flag |
| 2 | |
| 3 | const one_ok_gnu_arg_no_tail = ['-flip', '--g', '/path/to', '--mix', '-ver'] |
| 4 | const two_ok_gnu_arg_no_tail = ['-flip', '--g', '--sound=blop', '/path/to', '--mix', '-ver'] |
| 5 | |
| 6 | const one_ok_gnu_arg_tail = ['-flip', '--g', '/path/to', '--mix', '-ver', 'tail'] |
| 7 | const two_ok_gnu_arg_tail = ['-flip', '--g', '--sound=blop', '/path/to', '--mix', '-ver', 'tail'] |
| 8 | |
| 9 | struct Config { |
| 10 | mix bool |
| 11 | sound string |
| 12 | beep bool |
| 13 | path string @[tail] |
| 14 | } |
| 15 | |
| 16 | fn test_flag_relaxed_mode() { |
| 17 | // Test `mode: .relaxed` |
| 18 | config1, no_matches1 := flag.to_struct[Config](one_ok_gnu_arg_no_tail, mode: .relaxed)! |
| 19 | assert config1.mix == true |
| 20 | assert config1.sound == '' |
| 21 | assert config1.beep == false |
| 22 | assert config1.path == '' |
| 23 | assert no_matches1 == ['-flip', '--g', '/path/to', '-ver'] |
| 24 | |
| 25 | config2, no_matches2 := flag.to_struct[Config](two_ok_gnu_arg_no_tail, mode: .relaxed)! |
| 26 | assert config2.mix == true |
| 27 | assert config2.sound == 'blop' |
| 28 | assert config2.beep == false |
| 29 | assert config2.path == '' |
| 30 | assert no_matches2 == ['-flip', '--g', '/path/to', '-ver'] |
| 31 | |
| 32 | config3, no_matches3 := flag.to_struct[Config](one_ok_gnu_arg_tail, mode: .relaxed)! |
| 33 | assert config3.mix == true |
| 34 | assert config3.sound == '' |
| 35 | assert config3.beep == false |
| 36 | assert config3.path == 'tail' |
| 37 | assert no_matches3 == ['-flip', '--g', '/path/to', '-ver'] |
| 38 | |
| 39 | config4, no_matches4 := flag.to_struct[Config](two_ok_gnu_arg_tail, mode: .relaxed)! |
| 40 | assert config4.mix == true |
| 41 | assert config4.sound == 'blop' |
| 42 | assert config4.beep == false |
| 43 | assert config4.path == 'tail' |
| 44 | assert no_matches4 == ['-flip', '--g', '/path/to', '-ver'] |
| 45 | } |
| 46 | |