clasp-ruby 0.23.0.2 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/cr-example.rb +16 -16
- data/examples/flag_and_option_specifications.rb +15 -15
- data/examples/show_usage_and_version.rb +10 -11
- data/lib/clasp/arguments.rb +86 -87
- data/lib/clasp/clasp.rb +15 -11
- data/lib/clasp/cli.rb +135 -134
- data/lib/clasp/old_module.rb +8 -8
- data/lib/clasp/specifications.rb +325 -322
- data/lib/clasp/util/exceptions.rb +21 -22
- data/lib/clasp/util/value_parser.rb +99 -101
- data/lib/clasp/version.rb +12 -12
- data/lib/clasp-ruby.rb +8 -7
- data/lib/clasp.rb +8 -7
- data/test/scratch/test_list_command_line.rb +6 -6
- data/test/scratch/test_specifications.rb +14 -14
- data/test/scratch/test_usage.rb +5 -5
- data/test/scratch/test_usage_with_duplicate_specifications.rb +5 -5
- data/test/unit/tc_ARGV_rewrite.rb +36 -36
- data/test/unit/tc_arguments_1.rb +708 -708
- data/test/unit/tc_arguments_2.rb +43 -43
- data/test/unit/tc_arguments_3.rb +77 -77
- data/test/unit/tc_arguments_inspect.rb +55 -55
- data/test/unit/tc_cli.rb +4 -4
- data/test/unit/tc_default_value.rb +91 -91
- data/test/unit/tc_defaults_1.rb +38 -38
- data/test/unit/tc_examples_Arguments.rb +130 -130
- data/test/unit/tc_extras.rb +24 -24
- data/test/unit/tc_option_required.rb +38 -38
- data/test/unit/tc_option_value_aliases.rb +44 -44
- data/test/unit/tc_specifications.rb +7 -7
- data/test/unit/tc_typed_options.rb +200 -200
- data/test/unit/tc_usage.rb +69 -69
- data/test/unit/tc_with_action.rb +23 -23
- metadata +9 -8
@@ -10,301 +10,301 @@ require 'test/unit'
|
|
10
10
|
|
11
11
|
class Test_TypedOptionValues < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
if RUBY_VERSION < '2'
|
14
14
|
|
15
|
-
|
15
|
+
def assert_raise_with_message(type_spec, message_spec, *args, &block)
|
16
16
|
|
17
|
-
|
18
|
-
end
|
17
|
+
assert_raise(type_spec, *args, &block)
|
19
18
|
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_Integer_no_range
|
22
22
|
|
23
|
-
|
23
|
+
specifications = [
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
CLASP.Option('--level', default_value: 1234, constraint: { type: Integer })
|
26
|
+
]
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
# with no arguments
|
29
|
+
begin
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
argv = []
|
32
|
+
args = CLASP.parse argv, specifications
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
assert_equal 0, args.flags.size
|
35
|
+
assert_equal 0, args.options.size
|
36
|
+
assert_equal 0, args.values.size
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
# with default value
|
40
|
+
begin
|
41
41
|
|
42
|
-
|
42
|
+
argv = [ '--level=' ]
|
43
43
|
|
44
|
-
|
44
|
+
args = CLASP.parse argv, specifications
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
assert_equal 0, args.flags.size
|
47
|
+
assert_equal 1, args.options.size
|
48
|
+
assert_equal 0, args.values.size
|
49
49
|
|
50
|
-
|
50
|
+
opt = args.options[0]
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
assert_equal 0, opt.given_index
|
53
|
+
assert_equal specifications[0], opt.argument_specification
|
54
|
+
assert_equal '--level', opt.name
|
55
|
+
assert_equal '', opt.given_value
|
56
|
+
assert_equal 1234, opt.value
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
# with explicit value 0
|
60
|
+
begin
|
61
61
|
|
62
|
-
|
62
|
+
argv = [ '--level=0' ]
|
63
63
|
|
64
|
-
|
64
|
+
args = CLASP.parse argv, specifications
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
assert_equal 0, args.flags.size
|
67
|
+
assert_equal 1, args.options.size
|
68
|
+
assert_equal 0, args.values.size
|
69
69
|
|
70
|
-
|
70
|
+
opt = args.options[0]
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
assert_equal 0, opt.given_index
|
73
|
+
assert_equal specifications[0], opt.argument_specification
|
74
|
+
assert_equal '--level', opt.name
|
75
|
+
assert_equal '0', opt.given_value
|
76
|
+
assert_equal 0, opt.value
|
77
|
+
end
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
# with explicit value -100
|
80
|
+
begin
|
81
81
|
|
82
|
-
|
82
|
+
argv = [ '--level=-100' ]
|
83
83
|
|
84
|
-
|
84
|
+
args = CLASP.parse argv, specifications
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
assert_equal 0, args.flags.size
|
87
|
+
assert_equal 1, args.options.size
|
88
|
+
assert_equal 0, args.values.size
|
89
89
|
|
90
|
-
|
90
|
+
opt = args.options[0]
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
assert_equal 0, opt.given_index
|
93
|
+
assert_equal specifications[0], opt.argument_specification
|
94
|
+
assert_equal '--level', opt.name
|
95
|
+
assert_equal '-100', opt.given_value
|
96
|
+
assert_equal(-100, opt.value)
|
97
|
+
end
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
# with explicit value 123456789
|
100
|
+
begin
|
101
101
|
|
102
|
-
|
102
|
+
argv = [ '--level=123456789' ]
|
103
103
|
|
104
|
-
|
104
|
+
args = CLASP.parse argv, specifications
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
assert_equal 0, args.flags.size
|
107
|
+
assert_equal 1, args.options.size
|
108
|
+
assert_equal 0, args.values.size
|
109
109
|
|
110
|
-
|
110
|
+
opt = args.options[0]
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
assert_equal 0, opt.given_index
|
113
|
+
assert_equal specifications[0], opt.argument_specification
|
114
|
+
assert_equal '--level', opt.name
|
115
|
+
assert_equal '123456789', opt.given_value
|
116
|
+
assert_equal 123456789, opt.value
|
117
|
+
end
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
# with explicit value +123456789
|
120
|
+
begin
|
121
121
|
|
122
|
-
|
122
|
+
argv = [ '--level=+123456789' ]
|
123
123
|
|
124
|
-
|
124
|
+
args = CLASP.parse argv, specifications
|
125
125
|
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
assert_equal 0, args.flags.size
|
127
|
+
assert_equal 1, args.options.size
|
128
|
+
assert_equal 0, args.values.size
|
129
129
|
|
130
|
-
|
130
|
+
opt = args.options[0]
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
132
|
+
assert_equal 0, opt.given_index
|
133
|
+
assert_equal specifications[0], opt.argument_specification
|
134
|
+
assert_equal '--level', opt.name
|
135
|
+
assert_equal '+123456789', opt.given_value
|
136
|
+
assert_equal 123456789, opt.value
|
138
137
|
end
|
138
|
+
end
|
139
139
|
|
140
|
-
|
140
|
+
def test_Integer_positive
|
141
141
|
|
142
|
-
|
142
|
+
specifications = [
|
143
143
|
|
144
|
-
|
145
|
-
|
144
|
+
CLASP.Option('--level', default_value: 1234, constraint: { type: Integer, range: :positive })
|
145
|
+
]
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
# with no arguments
|
148
|
+
begin
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
argv = []
|
151
|
+
args = CLASP.parse argv, specifications
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
153
|
+
assert_equal 0, args.flags.size
|
154
|
+
assert_equal 0, args.options.size
|
155
|
+
assert_equal 0, args.values.size
|
156
|
+
end
|
157
157
|
|
158
|
-
|
159
|
-
|
158
|
+
# with default value
|
159
|
+
begin
|
160
160
|
|
161
|
-
|
161
|
+
argv = [ '--level=' ]
|
162
162
|
|
163
|
-
|
163
|
+
args = CLASP.parse argv, specifications
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
assert_equal 0, args.flags.size
|
166
|
+
assert_equal 1, args.options.size
|
167
|
+
assert_equal 0, args.values.size
|
168
168
|
|
169
|
-
|
169
|
+
opt = args.options[0]
|
170
170
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
171
|
+
assert_equal 0, opt.given_index
|
172
|
+
assert_equal specifications[0], opt.argument_specification
|
173
|
+
assert_equal '--level', opt.name
|
174
|
+
assert_equal '', opt.given_value
|
175
|
+
assert_equal 1234, opt.value
|
176
|
+
end
|
177
177
|
|
178
|
-
|
179
|
-
|
178
|
+
# with explicit value 0
|
179
|
+
begin
|
180
180
|
|
181
|
-
|
181
|
+
argv = [ '--level=0' ]
|
182
182
|
|
183
|
-
|
184
|
-
|
183
|
+
assert_raise_with_message(CLASP::Exceptions::IntegerOutOfRangeException, /\b0\b.*--level.*must be a positive integer/) { CLASP.parse argv, specifications }
|
184
|
+
end
|
185
185
|
|
186
|
-
|
187
|
-
|
186
|
+
# with explicit value -100
|
187
|
+
begin
|
188
188
|
|
189
|
-
|
189
|
+
argv = [ '--level=-100' ]
|
190
190
|
|
191
|
-
|
192
|
-
|
191
|
+
assert_raise_with_message(CLASP::Exceptions::IntegerOutOfRangeException, /-100\b.*--level.*must be a positive integer/) { CLASP.parse argv, specifications }
|
192
|
+
end
|
193
193
|
|
194
|
-
|
195
|
-
|
194
|
+
# with explicit value 123456789
|
195
|
+
begin
|
196
196
|
|
197
|
-
|
197
|
+
argv = [ '--level=123456789' ]
|
198
198
|
|
199
|
-
|
199
|
+
args = CLASP.parse argv, specifications
|
200
200
|
|
201
|
-
|
202
|
-
|
203
|
-
|
201
|
+
assert_equal 0, args.flags.size
|
202
|
+
assert_equal 1, args.options.size
|
203
|
+
assert_equal 0, args.values.size
|
204
204
|
|
205
|
-
|
205
|
+
opt = args.options[0]
|
206
206
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
207
|
+
assert_equal 0, opt.given_index
|
208
|
+
assert_equal specifications[0], opt.argument_specification
|
209
|
+
assert_equal '--level', opt.name
|
210
|
+
assert_equal '123456789', opt.given_value
|
211
|
+
assert_equal 123456789, opt.value
|
212
|
+
end
|
213
213
|
|
214
|
-
|
215
|
-
|
214
|
+
# with explicit value +123456789
|
215
|
+
begin
|
216
216
|
|
217
|
-
|
217
|
+
argv = [ '--level=+123456789' ]
|
218
218
|
|
219
|
-
|
219
|
+
args = CLASP.parse argv, specifications
|
220
220
|
|
221
|
-
|
222
|
-
|
223
|
-
|
221
|
+
assert_equal 0, args.flags.size
|
222
|
+
assert_equal 1, args.options.size
|
223
|
+
assert_equal 0, args.values.size
|
224
224
|
|
225
|
-
|
225
|
+
opt = args.options[0]
|
226
226
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
end
|
227
|
+
assert_equal 0, opt.given_index
|
228
|
+
assert_equal specifications[0], opt.argument_specification
|
229
|
+
assert_equal '--level', opt.name
|
230
|
+
assert_equal '+123456789', opt.given_value
|
231
|
+
assert_equal 123456789, opt.value
|
233
232
|
end
|
233
|
+
end
|
234
234
|
|
235
|
-
|
235
|
+
def test_Integer_range_values_range
|
236
236
|
|
237
|
-
|
237
|
+
specifications = [
|
238
238
|
|
239
|
-
|
240
|
-
|
239
|
+
CLASP.Option('--level', default_value: 1234, values_range: [ 1234, -1234, 7, 19 ], constraint: { type: Integer })
|
240
|
+
]
|
241
241
|
|
242
|
-
|
243
|
-
|
242
|
+
# with no arguments
|
243
|
+
begin
|
244
244
|
|
245
|
-
|
246
|
-
|
245
|
+
argv = []
|
246
|
+
args = CLASP.parse argv, specifications
|
247
247
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
248
|
+
assert_equal 0, args.flags.size
|
249
|
+
assert_equal 0, args.options.size
|
250
|
+
assert_equal 0, args.values.size
|
251
|
+
end
|
252
252
|
|
253
|
-
|
254
|
-
|
253
|
+
# with default value
|
254
|
+
begin
|
255
255
|
|
256
|
-
|
256
|
+
argv = [ '--level=' ]
|
257
257
|
|
258
|
-
|
258
|
+
args = CLASP.parse argv, specifications
|
259
259
|
|
260
|
-
|
261
|
-
|
262
|
-
|
260
|
+
assert_equal 0, args.flags.size
|
261
|
+
assert_equal 1, args.options.size
|
262
|
+
assert_equal 0, args.values.size
|
263
263
|
|
264
|
-
|
264
|
+
opt = args.options[0]
|
265
265
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
266
|
+
assert_equal 0, opt.given_index
|
267
|
+
assert_equal specifications[0], opt.argument_specification
|
268
|
+
assert_equal '--level', opt.name
|
269
|
+
assert_equal '', opt.given_value
|
270
|
+
assert_equal 1234, opt.value
|
271
|
+
end
|
272
272
|
|
273
|
-
|
274
|
-
|
273
|
+
# with explicit value 0
|
274
|
+
begin
|
275
275
|
|
276
|
-
|
276
|
+
argv = [ '--level=0' ]
|
277
277
|
|
278
|
-
|
279
|
-
|
278
|
+
assert_raise_with_message(CLASP::Exceptions::IntegerOutOfRangeException, /\b0\b.*--level.*does not fall within the required range/) { CLASP.parse argv, specifications }
|
279
|
+
end
|
280
280
|
|
281
|
-
|
282
|
-
|
281
|
+
spec0 = specifications[0]
|
282
|
+
values = spec0.values_range.sort[0]..spec0.values_range.sort[-1]
|
283
283
|
|
284
|
-
|
284
|
+
values.each do |val|
|
285
285
|
|
286
|
-
|
286
|
+
argv = [ "--level=#{val}" ]
|
287
287
|
|
288
|
-
|
288
|
+
if spec0.values_range.include? val
|
289
289
|
|
290
|
-
|
290
|
+
args = CLASP.parse argv, specifications
|
291
291
|
|
292
|
-
|
293
|
-
|
294
|
-
|
292
|
+
assert_equal 0, args.flags.size
|
293
|
+
assert_equal 1, args.options.size
|
294
|
+
assert_equal 0, args.values.size
|
295
295
|
|
296
|
-
|
296
|
+
opt = args.options[0]
|
297
297
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
298
|
+
assert_equal 0, opt.given_index
|
299
|
+
assert_equal specifications[0], opt.argument_specification
|
300
|
+
assert_equal '--level', opt.name
|
301
|
+
assert_equal val.to_s, opt.given_value
|
302
|
+
assert_equal val, opt.value
|
303
|
+
else
|
304
304
|
|
305
|
-
|
306
|
-
|
307
|
-
end
|
305
|
+
assert_raise_with_message(CLASP::Exceptions::IntegerOutOfRangeException, /#{val}\b.*--level.*does not fall within the required range/) { CLASP.parse argv, specifications }
|
306
|
+
end
|
308
307
|
end
|
308
|
+
end
|
309
309
|
end
|
310
310
|
|