cri 2.6.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,187 +1,211 @@
1
1
  # encoding: utf-8
2
2
 
3
- class Cri::CommandDSLTestCase < Cri::TestCase
4
-
5
- def test_create_command
6
- # Define
7
- dsl = Cri::CommandDSL.new
8
- dsl.instance_eval do
9
- name 'moo'
10
- usage 'dunno whatever'
11
- summary 'does stuff'
12
- description 'This command does a lot of stuff.'
13
-
14
- option :a, :aaa, 'opt a', :argument => :optional, :multiple => true
15
- required :b, :bbb, 'opt b'
16
- optional :c, :ccc, 'opt c'
17
- flag :d, :ddd, 'opt d'
18
- forbidden :e, :eee, 'opt e'
19
-
20
- run do |opts, args|
21
- $did_it_work = :probably
3
+ module Cri
4
+ class CommandDSLTestCase < Cri::TestCase
5
+ def test_create_command
6
+ # Define
7
+ dsl = Cri::CommandDSL.new
8
+ dsl.instance_eval do
9
+ name 'moo'
10
+ usage 'dunno whatever'
11
+ summary 'does stuff'
12
+ description 'This command does a lot of stuff.'
13
+
14
+ option :a, :aaa, 'opt a', :argument => :optional, :multiple => true
15
+ required :b, :bbb, 'opt b'
16
+ optional :c, :ccc, 'opt c'
17
+ flag :d, :ddd, 'opt d'
18
+ forbidden :e, :eee, 'opt e'
19
+ flag :f, :fff, 'opt f', :hidden => true
20
+
21
+ run do |_opts, _args|
22
+ $did_it_work = :probably
23
+ end
22
24
  end
23
- end
24
- command = dsl.command
25
-
26
- # Run
27
- $did_it_work = :sadly_not
28
- command.run(%w( -a x -b y -c -d -e ))
29
- assert_equal :probably, $did_it_work
30
-
31
- # Check
32
- assert_equal 'moo', command.name
33
- assert_equal 'dunno whatever', command.usage
34
- assert_equal 'does stuff', command.summary
35
- assert_equal 'This command does a lot of stuff.', command.description
36
-
37
- # Check options
38
- expected_option_definitions = Set.new([
39
- { :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional, :multiple => true, :block => nil },
40
- { :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required, :multiple => false, :block => nil },
41
- { :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional, :multiple => false, :block => nil },
42
- { :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :multiple => false, :block => nil },
43
- { :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :multiple => false, :block => nil }
25
+ command = dsl.command
26
+
27
+ # Run
28
+ $did_it_work = :sadly_not
29
+ command.run(%w( -a x -b y -c -d -e ))
30
+ assert_equal :probably, $did_it_work
31
+
32
+ # Check
33
+ assert_equal 'moo', command.name
34
+ assert_equal 'dunno whatever', command.usage
35
+ assert_equal 'does stuff', command.summary
36
+ assert_equal 'This command does a lot of stuff.', command.description
37
+
38
+ # Check options
39
+ expected_option_definitions = Set.new([
40
+ { :short => 'a', :long => 'aaa', :desc => 'opt a', :argument => :optional, :multiple => true, :hidden => false, :block => nil },
41
+ { :short => 'b', :long => 'bbb', :desc => 'opt b', :argument => :required, :multiple => false, :hidden => false, :block => nil },
42
+ { :short => 'c', :long => 'ccc', :desc => 'opt c', :argument => :optional, :multiple => false, :hidden => false, :block => nil },
43
+ { :short => 'd', :long => 'ddd', :desc => 'opt d', :argument => :forbidden, :multiple => false, :hidden => false, :block => nil },
44
+ { :short => 'e', :long => 'eee', :desc => 'opt e', :argument => :forbidden, :multiple => false, :hidden => false, :block => nil },
45
+ { :short => 'f', :long => 'fff', :desc => 'opt f', :argument => :forbidden, :multiple => false, :hidden => true, :block => nil },
44
46
  ])
45
- actual_option_definitions = Set.new(command.option_definitions)
46
- assert_equal expected_option_definitions, actual_option_definitions
47
- end
47
+ actual_option_definitions = Set.new(command.option_definitions)
48
+ assert_equal expected_option_definitions, actual_option_definitions
49
+ end
48
50
 
49
- def test_optional_options
50
- # Define
51
- dsl = Cri::CommandDSL.new
52
- dsl.instance_eval do
53
- name 'moo'
54
- usage 'dunno whatever'
55
- summary 'does stuff'
56
- description 'This command does a lot of stuff.'
51
+ def test_optional_options
52
+ # Define
53
+ dsl = Cri::CommandDSL.new
54
+ dsl.instance_eval do
55
+ name 'moo'
56
+ usage 'dunno whatever'
57
+ summary 'does stuff'
58
+ description 'This command does a lot of stuff.'
57
59
 
58
- flag :s, nil, 'short'
59
- flag nil, :long, 'long'
60
+ flag :s, nil, 'short'
61
+ flag nil, :long, 'long'
60
62
 
61
- run do |opts, args|
62
- $did_it_work = :probably
63
+ run do |_opts, _args|
64
+ $did_it_work = :probably
65
+ end
63
66
  end
64
- end
65
- command = dsl.command
66
-
67
- # Run
68
- $did_it_work = :sadly_not
69
- command.run(%w( -s --long ))
70
- assert_equal :probably, $did_it_work
71
-
72
- # Check options
73
- expected_option_definitions = Set.new([
74
- { :short => 's', :long => nil, :desc => 'short', :argument => :forbidden, :multiple => false, :block => nil },
75
- { :short => nil, :long => 'long', :desc => 'long', :argument => :forbidden, :multiple => false, :block => nil }
76
- ])
77
- actual_option_definitions = Set.new(command.option_definitions)
78
- assert_equal expected_option_definitions, actual_option_definitions
79
- end
67
+ command = dsl.command
80
68
 
81
- def test_multiple
82
- # Define
83
- dsl = Cri::CommandDSL.new
84
- dsl.instance_eval do
85
- flag :f, :flag, 'sample flag option', :multiple => true
86
- required :r, :required, 'sample required option', :multiple => true
87
- optional :o, :optional, 'sample optional option', :multiple => true
69
+ # Run
70
+ $did_it_work = :sadly_not
71
+ command.run(%w( -s --long ))
72
+ assert_equal :probably, $did_it_work
88
73
 
89
- run { |opts, args| }
74
+ # Check options
75
+ expected_option_definitions = Set.new([
76
+ { :short => 's', :long => nil, :desc => 'short', :argument => :forbidden, :multiple => false, :hidden => false, :block => nil },
77
+ { :short => nil, :long => 'long', :desc => 'long', :argument => :forbidden, :multiple => false, :hidden => false, :block => nil },
78
+ ])
79
+ actual_option_definitions = Set.new(command.option_definitions)
80
+ assert_equal expected_option_definitions, actual_option_definitions
90
81
  end
91
- command = dsl.command
92
-
93
- # Check options
94
- expected_option_definitions = Set.new([
95
- { :short => 'f', :long => 'flag', :desc => 'sample flag option', :argument => :forbidden, :multiple => true, :block => nil },
96
- { :short => 'r', :long => 'required', :desc => 'sample required option', :argument => :required, :multiple => true, :block => nil },
97
- { :short => 'o', :long => 'optional', :desc => 'sample optional option', :argument => :optional, :multiple => true, :block => nil },
98
- ])
99
- actual_option_definitions = Set.new(command.option_definitions)
100
- assert_equal expected_option_definitions, actual_option_definitions
101
- end
102
82
 
103
- def test_required_short_and_long
104
- # Define
105
- dsl = Cri::CommandDSL.new
106
- assert_raises ArgumentError do
83
+ def test_multiple
84
+ # Define
85
+ dsl = Cri::CommandDSL.new
107
86
  dsl.instance_eval do
108
- option nil, nil, 'meh'
87
+ flag :f, :flag, 'flag', :multiple => true
88
+ required :r, :required, 'req', :multiple => true
89
+ optional :o, :optional, 'opt', :multiple => true
90
+
91
+ run { |_opts, _args| }
109
92
  end
93
+ command = dsl.command
94
+
95
+ # Check options
96
+ expected_option_definitions = Set.new([
97
+ { :short => 'f', :long => 'flag', :desc => 'flag', :argument => :forbidden, :multiple => true, :hidden => false, :block => nil },
98
+ { :short => 'r', :long => 'required', :desc => 'req', :argument => :required, :multiple => true, :hidden => false, :block => nil },
99
+ { :short => 'o', :long => 'optional', :desc => 'opt', :argument => :optional, :multiple => true, :hidden => false, :block => nil },
100
+ ])
101
+ actual_option_definitions = Set.new(command.option_definitions)
102
+ assert_equal expected_option_definitions, actual_option_definitions
110
103
  end
111
- assert_raises ArgumentError do
104
+
105
+ def test_hidden
106
+ # Define
107
+ dsl = Cri::CommandDSL.new
112
108
  dsl.instance_eval do
113
- flag nil, nil, 'meh'
109
+ flag :f, :flag, 'flag', :hidden => true
110
+ required :r, :required, 'req', :hidden => true
111
+ optional :o, :optional, 'opt', :hidden => true
112
+
113
+ run { |_opts, _args| }
114
114
  end
115
+ command = dsl.command
116
+
117
+ # Check options
118
+ expected_option_definitions = Set.new([
119
+ { :short => 'f', :long => 'flag', :desc => 'flag', :argument => :forbidden, :multiple => false, :hidden => true, :block => nil },
120
+ { :short => 'r', :long => 'required', :desc => 'req', :argument => :required, :multiple => false, :hidden => true, :block => nil },
121
+ { :short => 'o', :long => 'optional', :desc => 'opt', :argument => :optional, :multiple => false, :hidden => true, :block => nil },
122
+ ])
123
+ actual_option_definitions = Set.new(command.option_definitions)
124
+ assert_equal expected_option_definitions, actual_option_definitions
115
125
  end
116
- assert_raises ArgumentError do
117
- dsl.instance_eval do
118
- required nil, nil, 'meh'
126
+
127
+ def test_required_short_and_long
128
+ # Define
129
+ dsl = Cri::CommandDSL.new
130
+ assert_raises ArgumentError do
131
+ dsl.instance_eval do
132
+ option nil, nil, 'meh'
133
+ end
119
134
  end
120
- end
121
- assert_raises ArgumentError do
122
- dsl.instance_eval do
123
- optional nil, nil, 'meh'
135
+ assert_raises ArgumentError do
136
+ dsl.instance_eval do
137
+ flag nil, nil, 'meh'
138
+ end
139
+ end
140
+ assert_raises ArgumentError do
141
+ dsl.instance_eval do
142
+ required nil, nil, 'meh'
143
+ end
144
+ end
145
+ assert_raises ArgumentError do
146
+ dsl.instance_eval do
147
+ optional nil, nil, 'meh'
148
+ end
124
149
  end
125
150
  end
126
- end
127
151
 
128
- def test_subcommand
129
- # Define
130
- dsl = Cri::CommandDSL.new
131
- dsl.instance_eval do
132
- name 'super'
133
- subcommand do |c|
134
- c.name 'sub'
152
+ def test_subcommand
153
+ # Define
154
+ dsl = Cri::CommandDSL.new
155
+ dsl.instance_eval do
156
+ name 'super'
157
+ subcommand do |c|
158
+ c.name 'sub'
159
+ end
135
160
  end
161
+ command = dsl.command
162
+
163
+ # Check
164
+ assert_equal 'super', command.name
165
+ assert_equal 1, command.subcommands.size
166
+ assert_equal 'sub', command.subcommands.to_a[0].name
136
167
  end
137
- command = dsl.command
138
168
 
139
- # Check
140
- assert_equal 'super', command.name
141
- assert_equal 1, command.subcommands.size
142
- assert_equal 'sub', command.subcommands.to_a[0].name
143
- end
169
+ def test_aliases
170
+ # Define
171
+ dsl = Cri::CommandDSL.new
172
+ dsl.instance_eval do
173
+ aliases :moo, :aah
174
+ end
175
+ command = dsl.command
144
176
 
145
- def test_aliases
146
- # Define
147
- dsl = Cri::CommandDSL.new
148
- dsl.instance_eval do
149
- aliases :moo, :aah
177
+ # Check
178
+ assert_equal %w( aah moo ), command.aliases.sort
150
179
  end
151
- command = dsl.command
152
-
153
- # Check
154
- assert_equal %w( aah moo ), command.aliases.sort
155
- end
156
180
 
157
- def test_run_arity
158
- dsl = Cri::CommandDSL.new
159
- assert_raises ArgumentError do
160
- dsl.instance_eval do
161
- run do |a, b, c, d, e|
181
+ def test_run_arity
182
+ dsl = Cri::CommandDSL.new
183
+ assert_raises ArgumentError do
184
+ dsl.instance_eval do
185
+ run do |_a, _b, _c, _d, _e|
186
+ end
162
187
  end
163
188
  end
164
189
  end
165
- end
166
190
 
167
- def test_runner
168
- # Define
169
- dsl = Cri::CommandDSL.new
170
- dsl.instance_eval <<-EOS
171
- class Cri::CommandDSLTestCaseCommandRunner < Cri::CommandRunner
172
- def run
173
- $works = arguments[0]
191
+ def test_runner
192
+ # Define
193
+ dsl = Cri::CommandDSL.new
194
+ dsl.instance_eval <<-EOS
195
+ class Cri::CommandDSLTestCaseCommandRunner < Cri::CommandRunner
196
+ def run
197
+ $did_it_work = arguments[0]
198
+ end
174
199
  end
175
- end
176
200
 
177
- runner Cri::CommandDSLTestCaseCommandRunner
178
- EOS
179
- command = dsl.command
201
+ runner Cri::CommandDSLTestCaseCommandRunner
202
+ EOS
203
+ command = dsl.command
180
204
 
181
- # Check
182
- $works = false
183
- command.run(%w( certainly ))
184
- assert_equal 'certainly', $works
205
+ # Check
206
+ $did_it_work = false
207
+ command.run(%w( certainly ))
208
+ assert_equal 'certainly', $did_it_work
209
+ end
185
210
  end
186
-
187
211
  end
@@ -1,32 +1,31 @@
1
1
  # encoding: utf-8
2
2
 
3
- class Cri::CommandRunnerTestCase < Cri::TestCase
4
-
5
- def setup
6
- super
7
-
8
- @options = { :vehicle => 'pig' }
9
- @arguments = %w( baby_monkey )
10
- @command = Cri::Command.new
11
- end
12
-
13
- def test_initialize
14
-
15
- runner = Cri::CommandRunner.new(@options, @arguments, @command)
3
+ module Cri
4
+ class CommandRunnerTestCase < Cri::TestCase
5
+ def setup
6
+ super
7
+
8
+ @options = { :vehicle => 'pig' }
9
+ @arguments = %w( baby_monkey )
10
+ @command = Cri::Command.new
11
+ end
16
12
 
17
- assert_equal @options, runner.options
18
- assert_equal @arguments, runner.arguments
19
- assert_equal @command, runner.command
20
- end
13
+ def test_initialize
14
+ runner = Cri::CommandRunner.new(@options, @arguments, @command)
21
15
 
22
- def test_call_run
23
- assert_raises(Cri::NotImplementedError) do
24
- Cri::CommandRunner.new(@options, @arguments, @command).call
16
+ assert_equal @options, runner.options
17
+ assert_equal @arguments, runner.arguments
18
+ assert_equal @command, runner.command
25
19
  end
26
20
 
27
- assert_raises(Cri::NotImplementedError) do
28
- Cri::CommandRunner.new(@options, @arguments, @command).run
21
+ def test_call_run
22
+ assert_raises(Cri::NotImplementedError) do
23
+ Cri::CommandRunner.new(@options, @arguments, @command).call
24
+ end
25
+
26
+ assert_raises(Cri::NotImplementedError) do
27
+ Cri::CommandRunner.new(@options, @arguments, @command).run
28
+ end
29
29
  end
30
30
  end
31
-
32
31
  end
@@ -1,294 +1,282 @@
1
1
  # encoding: utf-8
2
2
 
3
- class Cri::OptionParserTestCase < Cri::TestCase
3
+ module Cri
4
+ class OptionParserTestCase < Cri::TestCase
5
+ def test_parse_without_options
6
+ input = %w( foo bar baz )
7
+ definitions = []
4
8
 
5
- def test_parse_without_options
6
- input = %w( foo bar baz )
7
- definitions = []
8
-
9
- parser = Cri::OptionParser.parse(input, definitions)
10
-
11
- assert_equal({}, parser.options)
12
- assert_equal([ 'foo', 'bar', 'baz' ], parser.arguments)
13
- end
14
-
15
- def test_parse_with_invalid_option
16
- input = %w( foo -x )
17
- definitions = []
18
-
19
- result = nil
20
-
21
- assert_raises(Cri::OptionParser::IllegalOptionError) do
22
9
  parser = Cri::OptionParser.parse(input, definitions)
23
- end
24
- end
25
-
26
- def test_parse_with_unused_options
27
- input = %w( foo )
28
- definitions = [
29
- { :long => 'aaa', :short => 'a', :argument => :forbidden }
30
- ]
31
10
 
32
- parser = Cri::OptionParser.parse(input, definitions)
33
-
34
- assert(!parser.options[:aaa])
35
- end
36
-
37
- def test_parse_with_long_valueless_option
38
- input = %w( foo --aaa bar )
39
- definitions = [
40
- { :long => 'aaa', :short => 'a', :argument => :forbidden }
41
- ]
11
+ assert_equal({}, parser.options)
12
+ assert_equal(%w(foo bar baz), parser.arguments)
13
+ end
42
14
 
43
- parser = Cri::OptionParser.parse(input, definitions)
15
+ def test_parse_with_invalid_option
16
+ input = %w( foo -x )
17
+ definitions = []
44
18
 
45
- assert(parser.options[:aaa])
46
- assert_equal([ 'foo', 'bar' ], parser.arguments)
47
- end
48
-
49
- def test_parse_with_long_valueful_option
50
- input = %w( foo --aaa xxx bar )
51
- definitions = [
52
- { :long => 'aaa', :short => 'a', :argument => :required }
53
- ]
19
+ assert_raises(Cri::OptionParser::IllegalOptionError) do
20
+ Cri::OptionParser.parse(input, definitions)
21
+ end
22
+ end
54
23
 
55
- parser = Cri::OptionParser.parse(input, definitions)
24
+ def test_parse_with_unused_options
25
+ input = %w( foo )
26
+ definitions = [
27
+ { :long => 'aaa', :short => 'a', :argument => :forbidden },
28
+ ]
56
29
 
57
- assert_equal({ :aaa => 'xxx' }, parser.options)
58
- assert_equal([ 'foo', 'bar' ], parser.arguments)
59
- end
30
+ parser = Cri::OptionParser.parse(input, definitions)
60
31
 
61
- def test_parse_with_long_valueful_equalsign_option
62
- input = %w( foo --aaa=xxx bar )
63
- definitions = [
64
- { :long => 'aaa', :short => 'a', :argument => :required }
65
- ]
32
+ assert(!parser.options[:aaa])
33
+ end
66
34
 
67
- parser = Cri::OptionParser.parse(input, definitions)
35
+ def test_parse_with_long_valueless_option
36
+ input = %w( foo --aaa bar )
37
+ definitions = [
38
+ { :long => 'aaa', :short => 'a', :argument => :forbidden },
39
+ ]
68
40
 
69
- assert_equal({ :aaa => 'xxx' }, parser.options)
70
- assert_equal([ 'foo', 'bar' ], parser.arguments)
71
- end
41
+ parser = Cri::OptionParser.parse(input, definitions)
72
42
 
73
- def test_parse_with_long_valueful_option_with_missing_value
74
- input = %w( foo --aaa )
75
- definitions = [
76
- { :long => 'aaa', :short => 'a', :argument => :required }
77
- ]
43
+ assert(parser.options[:aaa])
44
+ assert_equal(%w(foo bar), parser.arguments)
45
+ end
78
46
 
79
- result = nil
47
+ def test_parse_with_long_valueful_option
48
+ input = %w( foo --aaa xxx bar )
49
+ definitions = [
50
+ { :long => 'aaa', :short => 'a', :argument => :required },
51
+ ]
80
52
 
81
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
82
53
  parser = Cri::OptionParser.parse(input, definitions)
83
- end
84
- end
85
54
 
86
- def test_parse_with_two_long_valueful_options
87
- input = %w( foo --all --port 2 )
88
- definitions = [
89
- { :long => 'all', :short => 'a', :argument => :required },
90
- { :long => 'port', :short => 'p', :argument => :required }
91
- ]
55
+ assert_equal({ :aaa => 'xxx' }, parser.options)
56
+ assert_equal(%w(foo bar), parser.arguments)
57
+ end
92
58
 
93
- result = nil
59
+ def test_parse_with_long_valueful_equalsign_option
60
+ input = %w( foo --aaa=xxx bar )
61
+ definitions = [
62
+ { :long => 'aaa', :short => 'a', :argument => :required },
63
+ ]
94
64
 
95
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
96
65
  parser = Cri::OptionParser.parse(input, definitions)
66
+
67
+ assert_equal({ :aaa => 'xxx' }, parser.options)
68
+ assert_equal(%w(foo bar), parser.arguments)
97
69
  end
98
- end
99
70
 
100
- def test_parse_with_long_valueless_option_with_optional_value
101
- input = %w( foo --aaa )
102
- definitions = [
103
- { :long => 'aaa', :short => 'a', :argument => :optional }
104
- ]
71
+ def test_parse_with_long_valueful_option_with_missing_value
72
+ input = %w( foo --aaa )
73
+ definitions = [
74
+ { :long => 'aaa', :short => 'a', :argument => :required },
75
+ ]
105
76
 
106
- parser = Cri::OptionParser.parse(input, definitions)
77
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
78
+ Cri::OptionParser.parse(input, definitions)
79
+ end
80
+ end
107
81
 
108
- assert(parser.options[:aaa])
109
- assert_equal([ 'foo' ], parser.arguments)
110
- end
82
+ def test_parse_with_two_long_valueful_options
83
+ input = %w( foo --all --port 2 )
84
+ definitions = [
85
+ { :long => 'all', :short => 'a', :argument => :required },
86
+ { :long => 'port', :short => 'p', :argument => :required },
87
+ ]
111
88
 
112
- def test_parse_with_long_valueful_option_with_optional_value
113
- input = %w( foo --aaa xxx )
114
- definitions = [
115
- { :long => 'aaa', :short => 'a', :argument => :optional }
116
- ]
89
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
90
+ Cri::OptionParser.parse(input, definitions)
91
+ end
92
+ end
117
93
 
118
- parser = Cri::OptionParser.parse(input, definitions)
94
+ def test_parse_with_long_valueless_option_with_optional_value
95
+ input = %w( foo --aaa )
96
+ definitions = [
97
+ { :long => 'aaa', :short => 'a', :argument => :optional },
98
+ ]
119
99
 
120
- assert_equal({ :aaa => 'xxx' }, parser.options)
121
- assert_equal([ 'foo' ], parser.arguments)
122
- end
100
+ parser = Cri::OptionParser.parse(input, definitions)
123
101
 
124
- def test_parse_with_long_valueless_option_with_optional_value_and_more_options
125
- input = %w( foo --aaa -b -c )
126
- definitions = [
127
- { :long => 'aaa', :short => 'a', :argument => :optional },
128
- { :long => 'bbb', :short => 'b', :argument => :forbidden },
129
- { :long => 'ccc', :short => 'c', :argument => :forbidden }
130
- ]
102
+ assert(parser.options[:aaa])
103
+ assert_equal(['foo'], parser.arguments)
104
+ end
131
105
 
132
- parser = Cri::OptionParser.parse(input, definitions)
106
+ def test_parse_with_long_valueful_option_with_optional_value
107
+ input = %w( foo --aaa xxx )
108
+ definitions = [
109
+ { :long => 'aaa', :short => 'a', :argument => :optional },
110
+ ]
133
111
 
134
- assert(parser.options[:aaa])
135
- assert(parser.options[:bbb])
136
- assert(parser.options[:ccc])
137
- assert_equal([ 'foo' ], parser.arguments)
138
- end
112
+ parser = Cri::OptionParser.parse(input, definitions)
139
113
 
140
- def test_parse_with_short_valueless_options
141
- input = %w( foo -a bar )
142
- definitions = [
143
- { :long => 'aaa', :short => 'a', :argument => :forbidden }
144
- ]
114
+ assert_equal({ :aaa => 'xxx' }, parser.options)
115
+ assert_equal(['foo'], parser.arguments)
116
+ end
145
117
 
146
- parser = Cri::OptionParser.parse(input, definitions)
118
+ def test_parse_with_long_valueless_option_with_optional_value_and_more_options
119
+ input = %w( foo --aaa -b -c )
120
+ definitions = [
121
+ { :long => 'aaa', :short => 'a', :argument => :optional },
122
+ { :long => 'bbb', :short => 'b', :argument => :forbidden },
123
+ { :long => 'ccc', :short => 'c', :argument => :forbidden },
124
+ ]
147
125
 
148
- assert(parser.options[:aaa])
149
- assert_equal([ 'foo', 'bar' ], parser.arguments)
150
- end
126
+ parser = Cri::OptionParser.parse(input, definitions)
151
127
 
152
- def test_parse_with_short_valueful_option_with_missing_value
153
- input = %w( foo -a )
154
- definitions = [
155
- { :long => 'aaa', :short => 'a', :argument => :required }
156
- ]
128
+ assert(parser.options[:aaa])
129
+ assert(parser.options[:bbb])
130
+ assert(parser.options[:ccc])
131
+ assert_equal(['foo'], parser.arguments)
132
+ end
157
133
 
158
- result = nil
134
+ def test_parse_with_short_valueless_options
135
+ input = %w( foo -a bar )
136
+ definitions = [
137
+ { :long => 'aaa', :short => 'a', :argument => :forbidden },
138
+ ]
159
139
 
160
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
161
140
  parser = Cri::OptionParser.parse(input, definitions)
162
- end
163
- end
164
-
165
- def test_parse_with_short_combined_valueless_options
166
- input = %w( foo -abc bar )
167
- definitions = [
168
- { :long => 'aaa', :short => 'a', :argument => :forbidden },
169
- { :long => 'bbb', :short => 'b', :argument => :forbidden },
170
- { :long => 'ccc', :short => 'c', :argument => :forbidden }
171
- ]
172
141
 
173
- parser = Cri::OptionParser.parse(input, definitions)
142
+ assert(parser.options[:aaa])
143
+ assert_equal(%w(foo bar), parser.arguments)
144
+ end
174
145
 
175
- assert(parser.options[:aaa])
176
- assert(parser.options[:bbb])
177
- assert(parser.options[:ccc])
178
- assert_equal([ 'foo', 'bar' ], parser.arguments)
179
- end
146
+ def test_parse_with_short_valueful_option_with_missing_value
147
+ input = %w( foo -a )
148
+ definitions = [
149
+ { :long => 'aaa', :short => 'a', :argument => :required },
150
+ ]
180
151
 
181
- def test_parse_with_short_combined_valueful_options_with_missing_value
182
- input = %w( foo -abc bar )
183
- definitions = [
184
- { :long => 'aaa', :short => 'a', :argument => :required },
185
- { :long => 'bbb', :short => 'b', :argument => :forbidden },
186
- { :long => 'ccc', :short => 'c', :argument => :forbidden }
187
- ]
152
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
153
+ Cri::OptionParser.parse(input, definitions)
154
+ end
155
+ end
188
156
 
189
- result = nil
157
+ def test_parse_with_short_combined_valueless_options
158
+ input = %w( foo -abc bar )
159
+ definitions = [
160
+ { :long => 'aaa', :short => 'a', :argument => :forbidden },
161
+ { :long => 'bbb', :short => 'b', :argument => :forbidden },
162
+ { :long => 'ccc', :short => 'c', :argument => :forbidden },
163
+ ]
190
164
 
191
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
192
165
  parser = Cri::OptionParser.parse(input, definitions)
166
+
167
+ assert(parser.options[:aaa])
168
+ assert(parser.options[:bbb])
169
+ assert(parser.options[:ccc])
170
+ assert_equal(%w(foo bar), parser.arguments)
193
171
  end
194
- end
195
172
 
196
- def test_parse_with_two_short_valueful_options
197
- input = %w( foo -a -p 2 )
198
- definitions = [
199
- { :long => 'all', :short => 'a', :argument => :required },
200
- { :long => 'port', :short => 'p', :argument => :required }
201
- ]
173
+ def test_parse_with_short_combined_valueful_options_with_missing_value
174
+ input = %w( foo -abc bar )
175
+ definitions = [
176
+ { :long => 'aaa', :short => 'a', :argument => :required },
177
+ { :long => 'bbb', :short => 'b', :argument => :forbidden },
178
+ { :long => 'ccc', :short => 'c', :argument => :forbidden },
179
+ ]
180
+
181
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
182
+ Cri::OptionParser.parse(input, definitions)
183
+ end
184
+ end
202
185
 
203
- result = nil
186
+ def test_parse_with_two_short_valueful_options
187
+ input = %w( foo -a -p 2 )
188
+ definitions = [
189
+ { :long => 'all', :short => 'a', :argument => :required },
190
+ { :long => 'port', :short => 'p', :argument => :required },
191
+ ]
204
192
 
205
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
206
- parser = Cri::OptionParser.parse(input, definitions)
193
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
194
+ Cri::OptionParser.parse(input, definitions)
195
+ end
207
196
  end
208
- end
209
197
 
210
- def test_parse_with_short_valueless_option_with_optional_value
211
- input = %w( foo -a )
212
- definitions = [
213
- { :long => 'aaa', :short => 'a', :argument => :optional }
214
- ]
198
+ def test_parse_with_short_valueless_option_with_optional_value
199
+ input = %w( foo -a )
200
+ definitions = [
201
+ { :long => 'aaa', :short => 'a', :argument => :optional },
202
+ ]
215
203
 
216
- parser = Cri::OptionParser.parse(input, definitions)
204
+ parser = Cri::OptionParser.parse(input, definitions)
217
205
 
218
- assert(parser.options[:aaa])
219
- assert_equal([ 'foo' ], parser.arguments)
220
- end
206
+ assert(parser.options[:aaa])
207
+ assert_equal(['foo'], parser.arguments)
208
+ end
221
209
 
222
- def test_parse_with_short_valueful_option_with_optional_value
223
- input = %w( foo -a xxx )
224
- definitions = [
225
- { :long => 'aaa', :short => 'a', :argument => :optional }
226
- ]
210
+ def test_parse_with_short_valueful_option_with_optional_value
211
+ input = %w( foo -a xxx )
212
+ definitions = [
213
+ { :long => 'aaa', :short => 'a', :argument => :optional },
214
+ ]
227
215
 
228
- parser = Cri::OptionParser.parse(input, definitions)
216
+ parser = Cri::OptionParser.parse(input, definitions)
229
217
 
230
- assert_equal({ :aaa => 'xxx' }, parser.options)
231
- assert_equal([ 'foo' ], parser.arguments)
232
- end
218
+ assert_equal({ :aaa => 'xxx' }, parser.options)
219
+ assert_equal(['foo'], parser.arguments)
220
+ end
233
221
 
234
- def test_parse_with_short_valueless_option_with_optional_value_and_more_options
235
- input = %w( foo -a -b -c )
236
- definitions = [
237
- { :long => 'aaa', :short => 'a', :argument => :optional },
238
- { :long => 'bbb', :short => 'b', :argument => :forbidden },
239
- { :long => 'ccc', :short => 'c', :argument => :forbidden }
240
- ]
222
+ def test_parse_with_short_valueless_option_with_optional_value_and_more_options
223
+ input = %w( foo -a -b -c )
224
+ definitions = [
225
+ { :long => 'aaa', :short => 'a', :argument => :optional },
226
+ { :long => 'bbb', :short => 'b', :argument => :forbidden },
227
+ { :long => 'ccc', :short => 'c', :argument => :forbidden },
228
+ ]
241
229
 
242
- parser = Cri::OptionParser.parse(input, definitions)
230
+ parser = Cri::OptionParser.parse(input, definitions)
243
231
 
244
- assert(parser.options[:aaa])
245
- assert(parser.options[:bbb])
246
- assert(parser.options[:ccc])
247
- assert_equal([ 'foo' ], parser.arguments)
248
- end
232
+ assert(parser.options[:aaa])
233
+ assert(parser.options[:bbb])
234
+ assert(parser.options[:ccc])
235
+ assert_equal(['foo'], parser.arguments)
236
+ end
249
237
 
250
- def test_parse_with_single_hyphen
251
- input = %w( foo - bar )
252
- definitions = []
238
+ def test_parse_with_single_hyphen
239
+ input = %w( foo - bar )
240
+ definitions = []
253
241
 
254
- parser = Cri::OptionParser.parse(input, definitions)
242
+ parser = Cri::OptionParser.parse(input, definitions)
255
243
 
256
- assert_equal({}, parser.options)
257
- assert_equal([ 'foo', '-', 'bar' ], parser.arguments)
258
- end
244
+ assert_equal({}, parser.options)
245
+ assert_equal(['foo', '-', 'bar'], parser.arguments)
246
+ end
259
247
 
260
- def test_parse_with_end_marker
261
- input = %w( foo bar -- -x --yyy -abc )
262
- definitions = []
248
+ def test_parse_with_end_marker
249
+ input = %w( foo bar -- -x --yyy -abc )
250
+ definitions = []
263
251
 
264
- parser = Cri::OptionParser.parse(input, definitions)
252
+ parser = Cri::OptionParser.parse(input, definitions)
265
253
 
266
- assert_equal({}, parser.options)
267
- assert_equal([ 'foo', 'bar', '-x', '--yyy', '-abc' ], parser.arguments)
268
- assert_equal([ 'foo', 'bar', '--', '-x', '--yyy', '-abc' ], parser.arguments.raw)
269
- end
254
+ assert_equal({}, parser.options)
255
+ assert_equal(['foo', 'bar', '-x', '--yyy', '-abc'], parser.arguments)
256
+ assert_equal(['foo', 'bar', '--', '-x', '--yyy', '-abc'], parser.arguments.raw)
257
+ end
270
258
 
271
- def test_parse_with_end_marker_between_option_key_and_value
272
- input = %w( foo --aaa -- zzz )
273
- definitions = [
274
- { :long => 'aaa', :short => 'a', :argument => :required }
275
- ]
259
+ def test_parse_with_end_marker_between_option_key_and_value
260
+ input = %w( foo --aaa -- zzz )
261
+ definitions = [
262
+ { :long => 'aaa', :short => 'a', :argument => :required },
263
+ ]
276
264
 
277
- assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
278
- parser = Cri::OptionParser.parse(input, definitions)
265
+ assert_raises(Cri::OptionParser::OptionRequiresAnArgumentError) do
266
+ Cri::OptionParser.parse(input, definitions)
267
+ end
279
268
  end
280
- end
281
269
 
282
- def test_parse_with_multiple_options
283
- input = %w( foo -o test -o test2 -v -v -v)
284
- definitions = [
285
- { :long => 'long', :short => 'o', :argument => :required, :multiple => true },
286
- { :long => 'verbose', :short => 'v', :multiple => true }
287
- ]
288
- parser = Cri::OptionParser.parse(input, definitions)
270
+ def test_parse_with_multiple_options
271
+ input = %w( foo -o test -o test2 -v -v -v)
272
+ definitions = [
273
+ { :long => 'long', :short => 'o', :argument => :required, :multiple => true },
274
+ { :long => 'verbose', :short => 'v', :multiple => true },
275
+ ]
276
+ parser = Cri::OptionParser.parse(input, definitions)
289
277
 
290
- assert_equal(['test', 'test2'], parser.options[:long])
291
- assert_equal(3, parser.options[:verbose].size)
278
+ assert_equal(%w(test test2), parser.options[:long])
279
+ assert_equal(3, parser.options[:verbose].size)
280
+ end
292
281
  end
293
-
294
282
  end