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
|
require 'spec_helper'
describe 'parslet/convenience' do
require 'parslet/convenience'
include Parslet
class FooParser < Parslet::Parser
rule(:foo) { str('foo') }
root(:foo)
end
describe 'parse_with_debug' do
let(:parser) { flexmock FooParser.new }
context 'internal' do
before(:each) do
# Suppress output.
#
parser.should_receive(:puts)
end
it 'should exist' do
lambda { parser.parse_with_debug('anything') }.should_not raise_error
end
it 'should catch ParseFailed exceptions' do
lambda { parser.parse_with_debug('bar') }.should_not raise_error
end
it 'should parse correct input like #parse' do
lambda { parser.parse_with_debug('foo') }.should_not raise_error
end
end
context 'output' do
it 'should puts once for tree output' do
parser.should_receive(:puts).once
parser.parse_with_debug('incorrect')
end
it "should puts once for the error on unconsumed input" do
parser.should_receive(:puts).once
parser.parse_with_debug('foobar')
end
end
it "should work for all parslets" do
str('foo').parse_with_debug('foo')
match['bar'].parse_with_debug('a')
end
end
end
|