Skip to content

Commit

Permalink
! Fixes another instance of hash mangling.
Browse files Browse the repository at this point in the history
No more logic errors
in that branch at least
until age comes to bear
  • Loading branch information
kschiess committed Jan 17, 2011
1 parent c64d174 commit 6bbbb67
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

+ Uses throw/catch internally for an order of magnitude increase in execution
speed.

! FIX: Parslet::Transform was wrongly fixed earlier - it now wont mangle
hashes anymore. (Blake Sweeney)

= 1.0.0 / 29Dez2010

Expand Down
3 changes: 2 additions & 1 deletion lib/parslet/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def element_match_ary_single(sequence, exp, bindings) # :nodoc:
end

def element_match_hash(tree, exp, bindings)
# p [:emh, tree, exp, bindings]
# Early failure when not all of the hash keys are matched.
return false unless exp.keys == tree.keys

# We iterate over expected pattern, since we demand that the keys that
# are there should be in tree as well.
Expand Down
4 changes: 2 additions & 2 deletions spec/parslet/pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def with_match_locals(pattern, &block)
bindings = p(pattern).match(exp)
bindings.should_not be_nil

block.call(bindings)
block.call(bindings) if block
end

# Can't use #match here, so I went to the Thesaurus.
Expand Down Expand Up @@ -143,7 +143,7 @@ def with_match_locals(pattern, &block)
end

it "should not match partially" do
exp.should_not match_with_bind(:a => simple(:x), :x => 'a')
Parslet::Pattern.new(:a => simple(:x)).match(exp).should be_nil
end
it "should match completely" do
exp.should match_with_bind({:a => simple(:x), :b => simple(:y)},
Expand Down
9 changes: 9 additions & 0 deletions spec/parslet/transform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ class OptimusPrime < Parslet::Transform
end
end

context "various transformations (regression)" do
context "hashes" do
it "are matched completely" do
transform.rule(:a => simple(:x)) { fail }
transform.apply(:a => 'a', :b => 'b')
end
end
end

context "when not using the bindings as hash, but as local variables" do
before(:each) do
transform.rule(simple(:x)) { A.new(x) }
Expand Down

0 comments on commit 6bbbb67

Please sign in to comment.