This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
forked from vito/mothership
/
combination_spec.rb
104 lines (93 loc) · 3.23 KB
/
combination_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require "spec_helper"
describe Mothership::Parser do
describe "combinations" do
describe "arguments & flags" do
it "parses flags placed after arguments" do
command(:flag => {}, :arg => { :argument => true }) do |c|
inputs(c, "foo", "--flag", "bar").should ==
{ :arg => "foo", :flag => "bar" }
end
end
it "parses flags placed before arguments" do
command(:flag => {}, :arg => { :argument => true }) do |c|
inputs(c, "--flag", "bar", "foo").should ==
{ :arg => "foo", :flag => "bar" }
end
end
it "parses flags placed between arguments" do
command([
[:flag, {}],
[:arg1, { :argument => true }],
[:arg2, { :argument => true }]]) do |c|
inputs(c, "foo", "--flag", "bar", "baz").should ==
{ :arg1 => "foo", :flag => "bar", :arg2 => "baz" }
end
end
it "skips parsing arguments that were passed as flags" do
command([
[:arg1, { :argument => true }],
[:arg2, { :argument => true }]]) do |c|
inputs(c, "baz", "--arg1", "foo").should ==
{ :arg1 => "foo", :arg2 => "baz" }
end
end
end
describe "arguments & splats" do
it "consumes the rest of the arguments" do
command([
[:foo, { :argument => :splat }],
[:bar, { :argument => true }]]) do |c|
proc {
inputs(c, "fizz", "buzz")
}.should raise_error(Mothership::MissingArgument)
end
end
it "consumes arguments after normal arguments" do
command([
[:foo, { :argument => true }],
[:bar, { :argument => :splat }]]) do |c|
inputs(c, "fizz", "buzz").should ==
{ :foo => "fizz", :bar => ["buzz"] }
end
end
it "appears empty when there are no arguments left after normal" do
command([
[:foo, { :argument => true }],
[:bar, { :argument => :splat }]]) do |c|
inputs(c, "fizz").should ==
{ :foo => "fizz", :bar => [] }
end
end
end
describe "splats & flags" do
it "parses flags placed after splats" do
command(:flag => {}, :arg => { :argument => :splat }) do |c|
inputs(c, "foo", "--flag", "bar").should ==
{ :arg => ["foo"], :flag => "bar" }
end
end
it "parses flags placed before splats" do
command(:flag => {}, :arg => { :argument => :splat }) do |c|
inputs(c, "--flag", "bar", "foo").should ==
{ :arg => ["foo"], :flag => "bar" }
end
end
it "parses flags placed between splat arguments" do
command([
[:flag, {}],
[:arg, { :argument => :splat }]]) do |c|
inputs(c, "foo", "--flag", "bar", "baz").should ==
{ :arg => ["foo", "baz"], :flag => "bar" }
end
end
it "skips parsing splats that were passed as flags" do
command([
[:arg1, { :argument => :splat }],
[:arg2, { :argument => true }]]) do |c|
inputs(c, "baz", "--arg1", "foo").should ==
{ :arg1 => ["foo"], :arg2 => "baz" }
end
end
end
end
end