Sha256: 6e65be5eaadd8b98fccb2a9a35deb152a4674f1bb2ab18b9d67f9495b707d86c

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe 'Result of a Parslet#parse' do
  include Parslet; extend Parslet
  
  describe "regression" do
    [
      # Behaviour with maybe-nil
      [str('foo').maybe >> str('bar'), "bar", "bar"],
      [str('bar') >> str('foo').maybe, "bar", 'bar'], 
      
      # These might be hard to understand; look at the result of 
      #   str.maybe >> str
      # and 
      #   str.maybe >> str first. 
      [(str('f').maybe >> str('b')).repeat, "bb", "bb"],
      [(str('b') >> str('f').maybe).repeat, "bb", 'bb'], 
      
      [str('a').as(:a) >> (str('b') >> str('c').as(:a)).repeat, 'abc', 
        [{:a=>'a'}, {:a=>'c'}]], 
      
      [str('a').as(:a).repeat >> str('b').as(:b).repeat, 'ab', [{:a=>'a'}, {:b=>'b'}]], 
      
      # Repetition behaviour / named vs. unnamed
      [str('f').repeat, '', ''], 
      [str('f').repeat.as(:f), '', {:f => []}],

      # Maybe behaviour / named vs. unnamed
      [str('f').maybe, '', ''], 
      [str('f').maybe.as(:f), '', {:f => nil}],
    ].each do |parslet, input, result|
      context "#{parslet.inspect}" do
        it "should parse \"#{input}\" into \"#{result}\"" do
          parslet.parse(input).should == result
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

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