File: parser_spec.rb

package info (click to toggle)
ruby-parslet 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 908 kB
  • ctags: 473
  • sloc: ruby: 5,220; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (6)
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
require 'spec_helper'

describe Parslet::Parser do
  include Parslet
  class FooParser < Parslet::Parser
    rule(:foo) { str('foo') }
    root(:foo)
  end
  
  describe "<- .root" do
    parser = Class.new(Parslet::Parser)
    parser.root :root_parslet
    
    it "should have defined a 'root' method, returning the root" do
      parser_instance = parser.new
      flexmock(parser_instance).should_receive(:root_parslet => :answer)
      
      parser_instance.root.should == :answer
    end 
  end
  it "should parse 'foo'" do
    FooParser.new.parse('foo').should == 'foo'
  end 
  context "composition" do
    let(:parser) { FooParser.new }
    it "should allow concatenation" do
      composite = parser >> str('bar')
      composite.should parse('foobar')
    end
  end
end