| 1 | import flag |
| 2 | |
| 3 | const posix_and_gnu_args_no_tail = ['-f'] |
| 4 | |
| 5 | const posix_and_gnu_args_tail = ['-f', 'tail'] |
| 6 | const posix_and_gnu_args_tails = ['-f', 'tail0', 'tail1', 'tail2'] |
| 7 | |
| 8 | const skip_posix_and_gnu_args_tail = ['skipme', '-f', 'tail'] |
| 9 | const skip_posix_and_gnu_args_tails = ['skipme', '-f', 'tail0', 'tail1', 'tail2'] |
| 10 | |
| 11 | struct ConfigTail { |
| 12 | mix bool |
| 13 | path string @[tail] |
| 14 | } |
| 15 | |
| 16 | struct ConfigTails { |
| 17 | mix bool |
| 18 | paths []string @[tail] |
| 19 | } |
| 20 | |
| 21 | fn test_flag_tail() { |
| 22 | // Test `@[tail]` edge-cases |
| 23 | config1, no_matches1 := flag.to_struct[ConfigTail](posix_and_gnu_args_tail)! |
| 24 | assert config1.mix == false |
| 25 | assert config1.path == 'tail' |
| 26 | assert no_matches1 == ['-f'] |
| 27 | |
| 28 | config2, no_matches2 := flag.to_struct[ConfigTails](posix_and_gnu_args_tails)! |
| 29 | assert config2.mix == false |
| 30 | assert config2.paths == ['tail0', 'tail1', 'tail2'] |
| 31 | assert no_matches2 == ['-f'] |
| 32 | |
| 33 | config3, no_matches3 := flag.to_struct[ConfigTail](skip_posix_and_gnu_args_tail, skip: 1)! |
| 34 | assert config3.mix == false |
| 35 | assert config3.path == 'tail' |
| 36 | assert no_matches3 == ['-f'] |
| 37 | |
| 38 | config4, no_matches4 := flag.to_struct[ConfigTails](skip_posix_and_gnu_args_tails, skip: 1)! |
| 39 | assert config4.mix == false |
| 40 | assert config4.paths == ['tail0', 'tail1', 'tail2'] |
| 41 | assert no_matches4 == ['-f'] |
| 42 | |
| 43 | config5, no_matches5 := flag.to_struct[ConfigTail](posix_and_gnu_args_tail, skip: 1)! |
| 44 | assert config5.mix == false |
| 45 | assert config5.path == 'tail' |
| 46 | assert no_matches5 == [] |
| 47 | |
| 48 | config6, no_matches6 := flag.to_struct[ConfigTails](posix_and_gnu_args_tails, skip: 1)! |
| 49 | assert config6.mix == false |
| 50 | assert config6.paths == ['tail0', 'tail1', 'tail2'] |
| 51 | assert no_matches6 == [] |
| 52 | |
| 53 | config7, no_matches7 := flag.to_struct[ConfigTail](posix_and_gnu_args_no_tail)! |
| 54 | assert config7.mix == false |
| 55 | assert config7.path == '' |
| 56 | assert no_matches7 == ['-f'] |
| 57 | |
| 58 | config8, no_matches8 := flag.to_struct[ConfigTail](posix_and_gnu_args_no_tail, skip: 1)! |
| 59 | assert config8.mix == false |
| 60 | assert config8.path == '' |
| 61 | assert no_matches8 == [] |
| 62 | } |
| 63 | |