Skip to content

Commit

Permalink
Create If Any pattern from negative Integer.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Nov 6, 2010
1 parent c948322 commit 888bd88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pegarus/ast/pattern.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ def pattern(spec)
when Array when Array
Set.new spec Set.new spec
when Integer when Integer
Any.new spec node = Any.new spec.abs
node = If.new node if spec < 0
node
when String when String
Character.new spec Character.new spec
when Pattern when Pattern
Expand Down
6 changes: 6 additions & 0 deletions spec/ast/pattern_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
Pegarus.pattern(5).should be_an_instance_of(Pegarus::Any) Pegarus.pattern(5).should be_an_instance_of(Pegarus::Any)
end end


it "returns an If Any pattern when passed a negative Integer" do
pat = Pegarus.pattern(-1)
pat.should be_an_instance_of(Pegarus::If)
pat.pattern.should be_an_instance_of(Pegarus::Any)
end

it "returns an Character pattern when passed a String" do it "returns an Character pattern when passed a String" do
Pegarus.pattern("abc").should be_an_instance_of(Pegarus::Character) Pegarus.pattern("abc").should be_an_instance_of(Pegarus::Character)
end end
Expand Down

0 comments on commit 888bd88

Please sign in to comment.