2 # Copyright (C) 2001-2008, The Perl Foundation.
7 languages/tcl/t/internal/select_switches.t
11 Excercise select_switches() - this sub handles switch parsing for various
16 % prove t/internal/select_switches.t
20 .HLL 'Tcl', 'tcl_group'
24 load_bytecode 'library/Test/More.pir'
26 # get the testing functions
27 .local pmc plan, ok, is
29 plan = find_global ['Test'; 'More'], 'plan'
30 ok = find_global ['Test'; 'More'], 'ok'
31 is = find_global ['Test'; 'More'], 'is'
33 load_bytecode 'languages/tcl/runtime/tcllib.pir'
39 message = 'does select_switches() exist in _tcl'
40 .local pmc select_switches
41 select_switches = get_root_global ['_tcl'], 'select_switches'
42 if select_switches goto ok_1
45 end # not much point in doing anything else...
51 .local pmc options, argv
52 options = new 'TclList'
61 message='exact match, single, leftover args'
62 $P1 = select_switches(options, argv)
65 $S1 = message . ' (value of switch key)'
69 $S1 = message . ' (no other options set)'
73 $S1 = message . ' (only one argv left)'
77 $S1 = message . ' (value of remaining argv)'
83 message='exact match, single, no leftover args'
84 $P1 = select_switches(options, argv)
87 $S1 = message . ' (value of switch key)'
91 $S1 = message . ' (no other options set)'
95 $S1 = message . ' (no args left)'
103 message='mutliple options, leftover args'
104 $P1 = select_switches(options, argv)
107 $S1 = message . ' (value of -joe key)'
111 $S1 = message . ' (value of -bar key)'
115 $S1 = message . ' (no other options set)'
119 $S1 = message . ' (only one argv left)'
123 $S1 = message . ' (value of remaining argv)'
124 is ($S0, 'what', $S1)
132 $P1 = select_switches(options, argv, 1)
135 $S1 = message . ' (value of -joe key)'
139 $S1 = message . ' (no other options set)'
143 $S1 = message . ' (only one argv left)'
147 $S1 = message . ' (value of remaining argv)'
148 is ($S0, '-bob', $S1)
153 argv[1] = 'bag_o_donuts'
154 message='invalid option specified, no exception'
155 $P1 = select_switches(options, argv)
158 $S1 = message . ' (value of -joke key)'
162 $S1 = message . ' (no other options set)'
166 $S1 = message . ' (two args left)'
170 $S1 = message . ' (argv[0])'
171 is ($S0, '-joke', $S1)
174 $S1 = message . ' (argv[1])'
175 is ($S0, 'bag_o_donuts', $S1)
180 argv[1] = 'bag_o_donuts'
181 message='invalid option specified, w/ exception'
184 $P1 = select_switches(options, argv, 0, 1)
191 get_results '0,0', $P2, $S2
193 is($S2, 'bad switch "-joke": must be -baz, -bob, or -joe', message)
198 argv[1] = 'bag_o_donuts'
199 message='invalid option specified, w/ exception and --'
202 $P1 = select_switches(options, argv, 1, 1)
209 get_results '0,0', $P2, $S2
211 is($S2, 'bad switch "-joke": must be -baz, -bob, -joe, or --', message)
216 argv[1] = 'bag_o_donuts'
217 message='invalid option specified, w/ exception, --, and override name'
220 $P1 = select_switches(options, argv, 1, 1, 'frob')
227 get_results '0,0', $P2, $S2
229 is($S2, 'bad frob "-joke": must be -baz, -bob, -joe, or --', message)
232 options[2] = 'joe:s' # change this to take a value..
236 argv[1] = 'bag_o_donuts'
238 message='switch with a value specified'
239 $P1 = select_switches(options, argv)
242 $S1 = message . ' (value of -joe key)'
243 is ($S2, 'bag_o_donuts', $S1)
246 $S1 = message . ' (no other options set)'
250 $S1 = message . ' (only one argv left)'
254 $S1 = message . ' (value of remaining argv)'
255 is ($S0, 'what', $S1)
258 options = new 'TclList'
264 argv[1] = 'bag_o_donuts'
265 message='invalid option specified, with choice of 2, w/ exception'
268 $P1 = select_switches(options, argv, 0, 1)
275 get_results '0,0', $P2, $S2
277 is($S2, 'bad switch "-fail": must be -good0 or -good1', message)
285 # vim: expandtab shiftwidth=4 ft=pir: