From f1f5f7c14f4aa6b98bd0bbc20e3acca38286401f Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Mon, 28 May 2012 20:51:21 +0100 Subject: 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 --- test/option_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test') 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/ } -- cgit v1.2.1