Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ parse_with_debug now works on all parslets

  • Loading branch information...
commit de4319205a9ae80b2ca2aaaec71e43376bf3d4f2 1 parent d1ba7d5
@kschiess kschiess authored
Showing with 14 additions and 17 deletions.
  1. +2 −0  HISTORY.txt
  2. +12 −17 spec/parslet/convenience_spec.rb
View
2  HISTORY.txt
@@ -6,6 +6,8 @@
+ No strings, only slices are returned as part of the parser result.
Parslet::Slice is almost a string class, but one that remembers the
source offset. This has also bought us a slight speedup.
+
+ + require 'parslet/convenience' now brings #parse_with_debug to all parslets.
= 1.1.1 / 4Feb2011
View
29 spec/parslet/convenience_spec.rb
@@ -2,6 +2,7 @@
describe 'parslet/convenience' do
require 'parslet/convenience'
+ include Parslet
class FooParser < Parslet::Parser
rule(:foo) { str('foo') }
@@ -9,40 +10,34 @@ class FooParser < Parslet::Parser
end
describe 'parse_with_debug' do
- before(:each) do
- @parser = flexmock FooParser.new
- end
+ let(:parser) { flexmock FooParser.new }
context 'internal' do
before(:each) do
# Suppress output.
#
- @parser.should_receive(:puts).zero_or_more_times
+ parser.should_receive(:puts)
end
it 'should exist' do
- lambda { @parser.parse_with_debug('anything') }.should_not raise_error(NoMethodError)
+ lambda { parser.parse_with_debug('anything') }.should_not raise_error(NoMethodError)
end
it 'should catch ParseFailed exceptions' do
- lambda { @parser.parse_with_debug('bar') }.should_not raise_error(Parslet::ParseFailed)
+ lambda { parser.parse_with_debug('bar') }.should_not raise_error(Parslet::ParseFailed)
end
it 'should parse correct input like #parse' do
- lambda { @parser.parse_with_debug('foo') }.should_not raise_error
+ lambda { parser.parse_with_debug('foo') }.should_not raise_error
end
end
context 'output' do
it 'should puts once for the error, and once for the tree' do
- @parser.should_receive(:puts).twice
+ parser.should_receive(:puts).twice
- @parser.parse_with_debug('incorrect')
+ parser.parse_with_debug('incorrect')
end
- # TODO Too specific?
- #
- # it 'should output the error and the error tree' do
- # @parser.should_receive(:puts).once.with('Expected "foo", but got "inc" at line 1 char 1')
- # @parser.should_receive(:puts).once.with('`- Expected "foo", but got "inc" at line 1 char 1')
- #
- # @parser.parse_with_debug('incorrect')
- # end
end
+ it "should work for all parslets" do
+ str('foo').parse_with_debug('foo')
+ match['bar'].parse_with_debug('a')
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.