diff options
author | Andrew Clemons <andrew.clemons@gmail.com> | 2016-04-04 15:10:25 +1200 |
---|---|---|
committer | Andrew Clemons <andrew.clemons@gmail.com> | 2016-04-04 15:21:45 +1200 |
commit | 7f6aef195716989d8fb7e66b1ca52e348551b67a (patch) | |
tree | 9adb41989b1ef1f982a0a0c2390648dbc215e392 /test | |
parent | c77f3c3d0ce9fcda28f3df3a789c166c622d16ee (diff) | |
download | slop-7f6aef195716989d8fb7e66b1ca52e348551b67a.tar.gz |
Support arguments to options with leading -
This allows negative values as arguments to numeric options and strings
starting with - for any other type.
Fixes #170
Fixes #179
Diffstat (limited to 'test')
-rw-r--r-- | test/parser_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/parser_test.rb b/test/parser_test.rb index 1099871..339a522 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -22,6 +22,27 @@ describe Slop::Parser do assert_equal 123, @result[:port] end + it "parses arg with leading -" do + @options.string "-t", "--text" + @result.parser.parse %w(--name=bob --text --sometext) + assert_equal "bob", @result[:name] + assert_equal "--sometext", @result[:text] + end + + it "parses negative integer" do + @options.integer "-p", "--port" + @result.parser.parse %w(--name=bob --port -123) + assert_equal "bob", @result[:name] + assert_equal(-123, @result[:port]) + end + + it "parses negative float" do + @options.float "-m", "--multiple" + @result.parser.parse %w(--name=bob -m -123.987) + assert_equal "bob", @result[:name] + assert_equal(-123.987, @result[:multiple]) + end + describe "parsing grouped short flags" do before do @options.bool "-q", "--quiet" |