diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 12:34:37 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 12:34:37 +0000 |
commit | f8895c3d2f962340c99d3211d71c9bb60bf69f18 (patch) | |
tree | b86ed6c5b2a041ceb380b8f768d621e244788661 /test | |
parent | 14458fb36b2bcc3ff10b837dc294e23c2cbefbb7 (diff) | |
download | slop-f8895c3d2f962340c99d3211d71c9bb60bf69f18.tar.gz |
Add more option types
Diffstat (limited to 'test')
-rw-r--r-- | test/types_test.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/types_test.rb b/test/types_test.rb new file mode 100644 index 0000000..e814ff9 --- /dev/null +++ b/test/types_test.rb @@ -0,0 +1,54 @@ +require 'test_helper' + +describe Slop::BoolOption do + before do + @options = Slop::Options.new + @age = @options.bool "--verbose" + @result = @options.parse %w(--verbose) + end + + it "returns true if used" do + assert_equal true, @result[:verbose] + end +end + +describe Slop::IntegerOption do + before do + @options = Slop::Options.new + @age = @options.integer "--age" + @result = @options.parse %w(--age 20) + end + + it "returns the value as an integer" do + assert_equal 20, @result[:age] + end + + it "returns nil for non-numbers by default" do + @result.parser.reset.parse %w(--age hello) + assert_equal nil, @result[:age] + end +end + +describe Slop::ArrayOption do + before do + @options = Slop::Options.new + @files = @options.array "--files" + @delim = @options.array "-d", delimiter: ":" + @result = @options.parse %w(--files foo.txt,bar.rb) + end + + it "parses comma separated args" do + assert_equal %w(foo.txt bar.rb), @result[:files] + end + + it "collects multiple option values" do + @result.parser.reset.parse %w(--files foo.txt --files bar.rb) + assert_equal %w(foo.txt bar.rb), @result[:files] + end + + it "can use a custom delimiter" do + @result.parser.reset.parse %w(-d foo.txt:bar.rb) + assert_equal %w(foo.txt bar.rb), @result[:d] + end +end + |