diff options
author | Lee Jarvis <lee@jarvis.co> | 2012-05-28 20:51:21 +0100 |
---|---|---|
committer | Lee Jarvis <lee@jarvis.co> | 2012-05-28 20:51:21 +0100 |
commit | f1f5f7c14f4aa6b98bd0bbc20e3acca38286401f (patch) | |
tree | bbea0b5938a54d30473dad9347a3924d607ba86b /test/option_test.rb | |
parent | da28d9300fb417391ce51f7b5f134639fa933b39 (diff) | |
download | slop-f1f5f7c14f4aa6b98bd0bbc20e3acca38286401f.tar.gz |
ensure range 'typecast' allows negative range values
When using `:optional_argument => true` with a negative range
(-1..10 for example) #process_item assumes that the option argument
looks like an option, thus setting the argument to nil instead of
the negative range.
This change now allows anything prefixed with a `-` following by a digit
could be a viable option argument.
In the future we should probably allow "numeric options" (of course
this commit would half rule that out, when using optional arguments,
at least). We could enable and disable this via configuration options
sent to Slop.new
closes #65
Diffstat (limited to 'test/option_test.rb')
-rw-r--r-- | test/option_test.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/test/option_test.rb b/test/option_test.rb index ff6a231..4751c16 100644 --- a/test/option_test.rb +++ b/test/option_test.rb @@ -78,6 +78,7 @@ class OptionTest < TestCase assert_equal (-1..10), option_value(%w/-r -1..10/, :r=, :as => Range) assert_equal (1..-10), option_value(%w/-r 1..-10/, :r=, :as => Range) assert_equal (1..1), option_value(%w/-r 1/, :r=, :as => Range) + assert_equal (-1..10), option_value(%w/-r -1..10/, :r, :as => Range, :optional_argument => true) opts = Slop.new(:strict => true) { on :r=, :as => Range } assert_raises(Slop::InvalidArgumentError) { opts.parse %w/-r abc/ } |