Skip to content

Commit 711f84f

Browse files
committed
write tests for parsing of list arguments
1 parent 29644b5 commit 711f84f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

spec/parser_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,29 @@
8989
parser.class.should == Parser
9090
end
9191
end
92+
93+
describe "parsing of lists" do
94+
it "should parse list of arguments separated by comma when given an array as default" do
95+
parser = Parser.new do |p|
96+
p.option :listarg, "List Argument", :default => []
97+
end
98+
99+
input = ['--listarg', 'foo,bar,baz']
100+
parser.process!(input)[:listarg].should == ['foo', 'bar', 'baz']
101+
end
102+
103+
it "should allow multiple argument lists" do
104+
parser = Parser.new do |p|
105+
p.option :first_listarg, "List Argument", :default => []
106+
p.option :second_listarg, "List Argument", :default => []
107+
end
108+
109+
input = ['-f', 'foo,bar,baz', '-s', 'blah,blah,blah']
110+
result = parser.process!(input)
111+
result[:first_listarg].should == ['foo', 'bar', 'baz']
112+
result[:second_listarg].should == ['blah', 'blah', 'blah']
113+
end
114+
end
92115

93116
describe "help message" do
94117
it "should show help message when called with --help or -h" do

0 commit comments

Comments
 (0)