getopt 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,79 +1,87 @@
1
- module Getopt
2
- class Std
3
- class Error < StandardError; end
4
-
5
- VERSION = '1.3.7'
6
-
7
- # Processes single character command line options with option
8
- # clustering. This information is parsed from ARGV and returned
9
- # as a hash, with the switch (minus the "-") as the key. The value
10
- # for that key is either true/false (boolean switches) or the argument
11
- # that was passed to the switch.
12
- #
13
- # Characters followed by a ":" require an argument. The rest are
14
- # considered boolean switches. If a switch that accepts an argument
15
- # appears more than once, the value for that key becomes an array
16
- # of values.
17
- #
18
- def self.getopts(switches)
19
- args = switches.split(/ */)
20
- hash = {}
21
-
22
- while !ARGV.empty? && ARGV.first =~ /^-(.)(.*)/s
23
- first, rest = $1, $2
24
- pos = switches.index(first)
25
-
26
- # Switches on the command line must appear among the characters
27
- # declared in +switches+.
28
- raise Error, "invalid option '#{first}'" unless pos
29
-
30
- if args[pos+1] == ":"
31
- ARGV.shift
32
- if rest.empty?
33
- rest = ARGV.shift
34
-
35
- # Ensure that switches requiring arguments actually
36
- # receive a (non-switch) argument.
37
- if rest.nil? || rest.empty?
38
- raise Error, "missing argument for '-#{args[pos]}'"
39
- end
40
-
41
- # Do not permit switches that require arguments to be
42
- # followed immediately by another switch.
43
- if args.include?(rest) || args.include?(rest[1..-1])
44
- err = "cannot use switch '#{rest}' as argument "
45
- err += "to another switch"
46
- raise Error, err
47
- end
48
-
49
- # For non boolean switches, arguments that appear multiple
50
- # times are converted to an array (or pushed onto an already
51
- # existant array).
52
- if hash.has_key?(first)
53
- hash[first] = [hash[first], rest].flatten
54
- else
55
- hash[first] = rest
56
- end
57
- else
58
- # Do not permit switches that require arguments to be
59
- # followed immediately by another switch.
60
- if args.include?(rest) || args.include?(rest[1..-1])
61
- err = "cannot use switch '#{rest}' as argument "
62
- err += "to another switch"
63
- raise Error, err
64
- end
65
- end
66
- else
67
- hash[first] = true # Boolean switch
68
- if rest.empty?
69
- ARGV.shift
70
- else
71
- ARGV[0] = "-#{rest}"
72
- end
73
- end
74
- end
75
-
76
- hash
77
- end
78
- end
79
- end
1
+ # The Getopt module serves as a namespace only
2
+ module Getopt
3
+ # The Getopt::Std class serves as a base class for the getopts method.
4
+ class Std
5
+ # The Getopt::Std::Error class is raised if there are any illegal
6
+ # command line arguments.
7
+ #
8
+ class Error < StandardError; end
9
+
10
+ # The version of this library
11
+ VERSION = '1.3.8'
12
+
13
+ # Processes single character command line options with option
14
+ # clustering. This information is parsed from ARGV and returned
15
+ # as a hash, with the switch (minus the "-") as the key. The value
16
+ # for that key is either true/false (boolean switches) or the argument
17
+ # that was passed to the switch.
18
+ #
19
+ # Characters followed by a ":" require an argument. The rest are
20
+ # considered boolean switches. If a switch that accepts an argument
21
+ # appears more than once, the value for that key becomes an array
22
+ # of values.
23
+ #
24
+ def self.getopts(switches)
25
+ args = switches.split(/ */)
26
+ hash = {}
27
+
28
+ while !ARGV.empty? && ARGV.first =~ /^-(.)(.*)/s
29
+ first, rest = $1, $2
30
+ pos = switches.index(first)
31
+
32
+ # Switches on the command line must appear among the characters
33
+ # declared in +switches+.
34
+ raise Error, "invalid option '#{first}'" unless pos
35
+
36
+ if args[pos+1] == ":"
37
+ ARGV.shift
38
+ if rest.empty?
39
+ rest = ARGV.shift
40
+
41
+ # Ensure that switches requiring arguments actually
42
+ # receive a (non-switch) argument.
43
+ if rest.nil? || rest.empty?
44
+ raise Error, "missing argument for '-#{args[pos]}'"
45
+ end
46
+
47
+ # Do not permit switches that require arguments to be
48
+ # followed immediately by another switch.
49
+ temp_args = args.map{ |e| "-#{e}" }
50
+
51
+ if temp_args.include?(rest) || temp_args.include?(rest[1..-1])
52
+ err = "cannot use switch '#{rest}' as argument "
53
+ err << "to another switch"
54
+ raise Error, err
55
+ end
56
+
57
+ # For non boolean switches, arguments that appear multiple
58
+ # times are converted to an array (or pushed onto an already
59
+ # existant array).
60
+ if hash.has_key?(first)
61
+ hash[first] = [hash[first], rest].flatten
62
+ else
63
+ hash[first] = rest
64
+ end
65
+ else
66
+ # Do not permit switches that require arguments to be
67
+ # followed immediately by another switch.
68
+ if args.include?(rest) || args.include?(rest[1..-1])
69
+ err = "cannot use switch '#{rest}' as argument "
70
+ err += "to another switch"
71
+ raise Error, err
72
+ end
73
+ end
74
+ else
75
+ hash[first] = true # Boolean switch
76
+ if rest.empty?
77
+ ARGV.shift
78
+ else
79
+ ARGV[0] = "-#{rest}"
80
+ end
81
+ end
82
+ end
83
+
84
+ hash
85
+ end
86
+ end
87
+ end
@@ -1,264 +1,267 @@
1
- #####################################################################
2
- # tc_getopt_long.rb
3
- #
4
- # Test suite for the getopt-long package. You should run this test
5
- # via the 'rake test' rake task.
6
- #####################################################################
7
- require 'test/unit'
8
- require 'getopt/long'
9
- include Getopt
10
-
11
- class TC_Getopt_Long < Test::Unit::TestCase
12
- def setup
13
- @opts = nil
14
- end
15
-
16
- def test_version
17
- assert_equal('1.3.7', Long::VERSION)
18
- end
19
-
20
- def test_constants
21
- assert_not_nil(BOOLEAN)
22
- assert_not_nil(OPTIONAL)
23
- assert_not_nil(REQUIRED)
24
- assert_not_nil(INCREMENT)
25
- end
26
-
27
- def test_getopts_basic
28
- assert_respond_to(Long, :getopts)
29
- assert_nothing_raised{
30
- Long.getopts(["--test"],["--help"],["--foo"])
31
- }
32
- assert_nothing_raised{
33
- Long.getopts(["--test", "-x"],["--help", "-y"],["--foo", "-z"])
34
- }
35
- assert_nothing_raised{
36
- Long.getopts(
37
- ["--test", "-x", BOOLEAN],
38
- ["--help", "-y", REQUIRED],
39
- ["--foo", "-z", OPTIONAL],
40
- ["--more", "-m", INCREMENT]
41
- )
42
- }
43
- assert_kind_of(Hash, Long.getopts("--test"))
44
- end
45
-
46
- def test_getopts_using_equals
47
- ARGV.push("--foo=hello","-b","world")
48
- assert_nothing_raised{
49
- @opts = Long.getopts(
50
- ["--foo", "-f", REQUIRED],
51
- ["--bar", "-b", OPTIONAL]
52
- )
53
- }
54
- assert_equal("hello", @opts["foo"])
55
- assert_equal("hello", @opts["f"])
56
- assert_equal("world", @opts["bar"])
57
- assert_equal("world", @opts["b"])
58
- end
59
-
60
- def test_getopts_long_embedded_hyphens
61
- ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
62
- assert_nothing_raised{
63
- @opts = Long.getopts(
64
- ['--foo-bar', '-f', REQUIRED],
65
- ['--test1-test2-test3', '-t', REQUIRED]
66
- )
67
- }
68
- assert_equal('hello', @opts['foo-bar'])
69
- assert_equal('hello', @opts['f'])
70
- assert_equal('world', @opts['test1-test2-test3'])
71
- assert_equal('world', @opts['t'])
72
- end
73
-
74
- def test_getopts_long_embedded_hyphens_using_equals_sign
75
- ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
76
- assert_nothing_raised{
77
- @opts = Long.getopts(
78
- ['--foo-bar', '-f', REQUIRED],
79
- ['--test1-test2-test3', '-t', REQUIRED]
80
- )
81
- }
82
- assert_equal('hello', @opts['foo-bar'])
83
- assert_equal('hello', @opts['f'])
84
- assert_equal('world', @opts['test1-test2-test3'])
85
- assert_equal('world', @opts['t'])
86
- end
87
-
88
- def test_getopts_short_switch_squished
89
- ARGV.push("-f", "hello", "-bworld")
90
- assert_nothing_raised{
91
- @opts = Long.getopts(
92
- ["--foo", "-f", REQUIRED],
93
- ["--bar", "-b", OPTIONAL]
94
- )
95
- }
96
- assert_equal("hello", @opts["f"])
97
- assert_equal("world", @opts["b"])
98
- end
99
-
100
- def test_getopts_increment_type
101
- ARGV.push("-m","-m")
102
- assert_nothing_raised{
103
- @opts = Long.getopts(["--more", "-m", INCREMENT])
104
- }
105
- assert_equal(2, @opts["more"])
106
- assert_equal(2, @opts["m"])
107
- end
108
-
109
- def test_switches_exist
110
- ARGV.push("--verbose","--test","--foo")
111
- assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
112
- assert_equal(true, @opts.has_key?("verbose"))
113
- assert_equal(true, @opts.has_key?("test"))
114
- assert_equal(true, @opts.has_key?("foo"))
115
- end
116
-
117
- def test_short_switch_synonyms
118
- ARGV.push("--verbose","--test","--foo")
119
- assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
120
- assert_equal(true, @opts.has_key?("v"))
121
- assert_equal(true, @opts.has_key?("t"))
122
- assert_equal(true, @opts.has_key?("f"))
123
- end
124
-
125
- def test_short_switch_synonyms_with_explicit_types
126
- ARGV.push("--verbose", "--test", "hello", "--foo")
127
- assert_nothing_raised{
128
- @opts = Long.getopts(
129
- ["--verbose", BOOLEAN],
130
- ["--test", REQUIRED],
131
- ["--foo", BOOLEAN]
132
- )
133
- }
134
- assert(@opts.has_key?("v"))
135
- assert(@opts.has_key?("t"))
136
- assert(@opts.has_key?("f"))
137
- end
138
-
139
- def test_switches_with_required_arguments
140
- ARGV.push("--foo","1","--bar","hello")
141
- assert_nothing_raised{
142
- @opts = Long.getopts(
143
- ["--foo", "-f", REQUIRED],
144
- ["--bar", "-b", REQUIRED]
145
- )
146
- }
147
- assert_equal({"foo"=>"1", "bar"=>"hello", "f"=>"1", "b"=>"hello"}, @opts)
148
- end
149
-
150
- def test_compressed_switches
151
- ARGV.push("-fb")
152
- assert_nothing_raised{
153
- @opts = Long.getopts(
154
- ["--foo", "-f", BOOLEAN],
155
- ["--bar", "-b", BOOLEAN]
156
- )
157
- }
158
- assert_equal({"foo"=>true, "f"=>true, "b"=>true, "bar"=>true}, @opts)
159
- end
160
-
161
- def test_compress_switches_with_required_arg
162
- ARGV.push("-xf", "foo.txt")
163
- assert_nothing_raised{
164
- @opts = Long.getopts(
165
- ["--expand", "-x", BOOLEAN],
166
- ["--file", "-f", REQUIRED]
167
- )
168
- }
169
- assert_equal(
170
- {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
171
- )
172
- end
173
-
174
- def test_compress_switches_with_compressed_required_arg
175
- ARGV.push("-xffoo.txt")
176
- assert_nothing_raised{
177
- @opts = Long.getopts(
178
- ["--expand", "-x", BOOLEAN],
179
- ["--file", "-f", REQUIRED]
180
- )
181
- }
182
- assert_equal(
183
- {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
184
- )
185
- end
186
-
187
- def test_compress_switches_with_optional_arg_not_defined
188
- ARGV.push("-xf")
189
- assert_nothing_raised{
190
- @opts = Long.getopts(
191
- ["--expand", "-x", BOOLEAN],
192
- ["--file", "-f", OPTIONAL]
193
- )
194
- }
195
- assert_equal(
196
- {"x"=>true, "expand"=>true, "f"=>nil, "file"=>nil}, @opts
197
- )
198
- end
199
-
200
- def test_compress_switches_with_optional_arg
201
- ARGV.push("-xf", "boo.txt")
202
- assert_nothing_raised{
203
- @opts = Long.getopts(
204
- ["--expand", "-x", BOOLEAN],
205
- ["--file", "-f", OPTIONAL]
206
- )
207
- }
208
- assert_equal(
209
- {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
210
- )
211
- end
212
-
213
- def test_compress_switches_with_compressed_optional_arg
214
- ARGV.push("-xfboo.txt")
215
- assert_nothing_raised{
216
- @opts = Long.getopts(
217
- ["--expand", "-x", BOOLEAN],
218
- ["--file", "-f", OPTIONAL]
219
- )
220
- }
221
- assert_equal(
222
- {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
223
- )
224
- end
225
-
226
- def test_compressed_short_and_long_mixed
227
- ARGV.push("-xb", "--file", "boo.txt", "-v")
228
- assert_nothing_raised{
229
- @opts = Long.getopts(
230
- ["--expand", "-x", BOOLEAN],
231
- ["--verbose", "-v", BOOLEAN],
232
- ["--file", "-f", REQUIRED],
233
- ["--bar", "-b", OPTIONAL]
234
- )
235
- assert_equal(
236
- { "x"=>true, "expand"=>true,
237
- "v"=>true, "verbose"=>true,
238
- "f"=>"boo.txt", "file"=>"boo.txt",
239
- "b"=>nil, "bar"=>nil
240
- },
241
- @opts
242
- )
243
- }
244
- end
245
-
246
- def test_multiple_similar_long_switches_with_no_short_switches
247
- ARGV.push('--to','1','--too','2','--tooo','3')
248
- assert_nothing_raised{
249
- @opts = Long.getopts(
250
- ["--to", REQUIRED],
251
- ["--too", REQUIRED],
252
- ["--tooo", REQUIRED]
253
- )
254
- }
255
- assert_equal('1', @opts['to'])
256
- assert_equal('2', @opts['too'])
257
- assert_equal('3', @opts['tooo'])
258
- end
259
-
260
- def teardown
261
- @opts = nil
262
- ARGV.clear
263
- end
264
- end
1
+ #####################################################################
2
+ # tc_getopt_long.rb
3
+ #
4
+ # Test suite for the getopt-long package. You should run this test
5
+ # via the 'rake test' rake task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'getopt/long'
12
+ include Getopt
13
+
14
+ class TC_Getopt_Long < Test::Unit::TestCase
15
+ def setup
16
+ @opts = nil
17
+ end
18
+
19
+ def test_version
20
+ assert_equal('1.3.7', Long::VERSION)
21
+ end
22
+
23
+ def test_constants
24
+ assert_not_nil(BOOLEAN)
25
+ assert_not_nil(OPTIONAL)
26
+ assert_not_nil(REQUIRED)
27
+ assert_not_nil(INCREMENT)
28
+ end
29
+
30
+ def test_getopts_basic
31
+ assert_respond_to(Long, :getopts)
32
+ assert_nothing_raised{
33
+ Long.getopts(["--test"],["--help"],["--foo"])
34
+ }
35
+ assert_nothing_raised{
36
+ Long.getopts(["--test", "-x"],["--help", "-y"],["--foo", "-z"])
37
+ }
38
+ assert_nothing_raised{
39
+ Long.getopts(
40
+ ["--test", "-x", BOOLEAN],
41
+ ["--help", "-y", REQUIRED],
42
+ ["--foo", "-z", OPTIONAL],
43
+ ["--more", "-m", INCREMENT]
44
+ )
45
+ }
46
+ assert_kind_of(Hash, Long.getopts("--test"))
47
+ end
48
+
49
+ def test_getopts_using_equals
50
+ ARGV.push("--foo=hello","-b","world")
51
+ assert_nothing_raised{
52
+ @opts = Long.getopts(
53
+ ["--foo", "-f", REQUIRED],
54
+ ["--bar", "-b", OPTIONAL]
55
+ )
56
+ }
57
+ assert_equal("hello", @opts["foo"])
58
+ assert_equal("hello", @opts["f"])
59
+ assert_equal("world", @opts["bar"])
60
+ assert_equal("world", @opts["b"])
61
+ end
62
+
63
+ def test_getopts_long_embedded_hyphens
64
+ ARGV.push('--foo-bar', 'hello', '--test1-test2-test3', 'world')
65
+ assert_nothing_raised{
66
+ @opts = Long.getopts(
67
+ ['--foo-bar', '-f', REQUIRED],
68
+ ['--test1-test2-test3', '-t', REQUIRED]
69
+ )
70
+ }
71
+ assert_equal('hello', @opts['foo-bar'])
72
+ assert_equal('hello', @opts['f'])
73
+ assert_equal('world', @opts['test1-test2-test3'])
74
+ assert_equal('world', @opts['t'])
75
+ end
76
+
77
+ def test_getopts_long_embedded_hyphens_using_equals_sign
78
+ ARGV.push('--foo-bar=hello', '--test1-test2-test3=world')
79
+ assert_nothing_raised{
80
+ @opts = Long.getopts(
81
+ ['--foo-bar', '-f', REQUIRED],
82
+ ['--test1-test2-test3', '-t', REQUIRED]
83
+ )
84
+ }
85
+ assert_equal('hello', @opts['foo-bar'])
86
+ assert_equal('hello', @opts['f'])
87
+ assert_equal('world', @opts['test1-test2-test3'])
88
+ assert_equal('world', @opts['t'])
89
+ end
90
+
91
+ def test_getopts_short_switch_squished
92
+ ARGV.push("-f", "hello", "-bworld")
93
+ assert_nothing_raised{
94
+ @opts = Long.getopts(
95
+ ["--foo", "-f", REQUIRED],
96
+ ["--bar", "-b", OPTIONAL]
97
+ )
98
+ }
99
+ assert_equal("hello", @opts["f"])
100
+ assert_equal("world", @opts["b"])
101
+ end
102
+
103
+ def test_getopts_increment_type
104
+ ARGV.push("-m","-m")
105
+ assert_nothing_raised{
106
+ @opts = Long.getopts(["--more", "-m", INCREMENT])
107
+ }
108
+ assert_equal(2, @opts["more"])
109
+ assert_equal(2, @opts["m"])
110
+ end
111
+
112
+ def test_switches_exist
113
+ ARGV.push("--verbose","--test","--foo")
114
+ assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
115
+ assert_equal(true, @opts.has_key?("verbose"))
116
+ assert_equal(true, @opts.has_key?("test"))
117
+ assert_equal(true, @opts.has_key?("foo"))
118
+ end
119
+
120
+ def test_short_switch_synonyms
121
+ ARGV.push("--verbose","--test","--foo")
122
+ assert_nothing_raised{ @opts = Long.getopts("--verbose --test --foo") }
123
+ assert_equal(true, @opts.has_key?("v"))
124
+ assert_equal(true, @opts.has_key?("t"))
125
+ assert_equal(true, @opts.has_key?("f"))
126
+ end
127
+
128
+ def test_short_switch_synonyms_with_explicit_types
129
+ ARGV.push("--verbose", "--test", "hello", "--foo")
130
+ assert_nothing_raised{
131
+ @opts = Long.getopts(
132
+ ["--verbose", BOOLEAN],
133
+ ["--test", REQUIRED],
134
+ ["--foo", BOOLEAN]
135
+ )
136
+ }
137
+ assert(@opts.has_key?("v"))
138
+ assert(@opts.has_key?("t"))
139
+ assert(@opts.has_key?("f"))
140
+ end
141
+
142
+ def test_switches_with_required_arguments
143
+ ARGV.push("--foo","1","--bar","hello")
144
+ assert_nothing_raised{
145
+ @opts = Long.getopts(
146
+ ["--foo", "-f", REQUIRED],
147
+ ["--bar", "-b", REQUIRED]
148
+ )
149
+ }
150
+ assert_equal({"foo"=>"1", "bar"=>"hello", "f"=>"1", "b"=>"hello"}, @opts)
151
+ end
152
+
153
+ def test_compressed_switches
154
+ ARGV.push("-fb")
155
+ assert_nothing_raised{
156
+ @opts = Long.getopts(
157
+ ["--foo", "-f", BOOLEAN],
158
+ ["--bar", "-b", BOOLEAN]
159
+ )
160
+ }
161
+ assert_equal({"foo"=>true, "f"=>true, "b"=>true, "bar"=>true}, @opts)
162
+ end
163
+
164
+ def test_compress_switches_with_required_arg
165
+ ARGV.push("-xf", "foo.txt")
166
+ assert_nothing_raised{
167
+ @opts = Long.getopts(
168
+ ["--expand", "-x", BOOLEAN],
169
+ ["--file", "-f", REQUIRED]
170
+ )
171
+ }
172
+ assert_equal(
173
+ {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
174
+ )
175
+ end
176
+
177
+ def test_compress_switches_with_compressed_required_arg
178
+ ARGV.push("-xffoo.txt")
179
+ assert_nothing_raised{
180
+ @opts = Long.getopts(
181
+ ["--expand", "-x", BOOLEAN],
182
+ ["--file", "-f", REQUIRED]
183
+ )
184
+ }
185
+ assert_equal(
186
+ {"x"=>true, "expand"=>true, "f"=>"foo.txt", "file"=>"foo.txt"}, @opts
187
+ )
188
+ end
189
+
190
+ def test_compress_switches_with_optional_arg_not_defined
191
+ ARGV.push("-xf")
192
+ assert_nothing_raised{
193
+ @opts = Long.getopts(
194
+ ["--expand", "-x", BOOLEAN],
195
+ ["--file", "-f", OPTIONAL]
196
+ )
197
+ }
198
+ assert_equal(
199
+ {"x"=>true, "expand"=>true, "f"=>nil, "file"=>nil}, @opts
200
+ )
201
+ end
202
+
203
+ def test_compress_switches_with_optional_arg
204
+ ARGV.push("-xf", "boo.txt")
205
+ assert_nothing_raised{
206
+ @opts = Long.getopts(
207
+ ["--expand", "-x", BOOLEAN],
208
+ ["--file", "-f", OPTIONAL]
209
+ )
210
+ }
211
+ assert_equal(
212
+ {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
213
+ )
214
+ end
215
+
216
+ def test_compress_switches_with_compressed_optional_arg
217
+ ARGV.push("-xfboo.txt")
218
+ assert_nothing_raised{
219
+ @opts = Long.getopts(
220
+ ["--expand", "-x", BOOLEAN],
221
+ ["--file", "-f", OPTIONAL]
222
+ )
223
+ }
224
+ assert_equal(
225
+ {"x"=>true, "expand"=>true, "f"=>"boo.txt", "file"=>"boo.txt"}, @opts
226
+ )
227
+ end
228
+
229
+ def test_compressed_short_and_long_mixed
230
+ ARGV.push("-xb", "--file", "boo.txt", "-v")
231
+ assert_nothing_raised{
232
+ @opts = Long.getopts(
233
+ ["--expand", "-x", BOOLEAN],
234
+ ["--verbose", "-v", BOOLEAN],
235
+ ["--file", "-f", REQUIRED],
236
+ ["--bar", "-b", OPTIONAL]
237
+ )
238
+ assert_equal(
239
+ { "x"=>true, "expand"=>true,
240
+ "v"=>true, "verbose"=>true,
241
+ "f"=>"boo.txt", "file"=>"boo.txt",
242
+ "b"=>nil, "bar"=>nil
243
+ },
244
+ @opts
245
+ )
246
+ }
247
+ end
248
+
249
+ def test_multiple_similar_long_switches_with_no_short_switches
250
+ ARGV.push('--to','1','--too','2','--tooo','3')
251
+ assert_nothing_raised{
252
+ @opts = Long.getopts(
253
+ ["--to", REQUIRED],
254
+ ["--too", REQUIRED],
255
+ ["--tooo", REQUIRED]
256
+ )
257
+ }
258
+ assert_equal('1', @opts['to'])
259
+ assert_equal('2', @opts['too'])
260
+ assert_equal('3', @opts['tooo'])
261
+ end
262
+
263
+ def teardown
264
+ @opts = nil
265
+ ARGV.clear
266
+ end
267
+ end