Sha256: 75eca8a2defe7178c7cea53518d520d5a168327d8b582ecc6cc0751d4026e184

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
parslet-2.0.0 spec/parslet/convenience_spec.rb
parslet-1.8.2 spec/parslet/convenience_spec.rb
parslet-1.8.1 spec/parslet/convenience_spec.rb
parslet-1.8.0 spec/parslet/convenience_spec.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/spec/parslet/convenience_spec.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/spec/parslet/convenience_spec.rb
parslet-1.7.1 spec/parslet/convenience_spec.rb