File: lookahead_spec.rb

package info (click to toggle)
ruby-parslet 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: ruby: 6,157; sh: 8; javascript: 3; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 760 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
require 'spec_helper'

describe Parslet::Atoms::Lookahead do
  include Parslet
  
  describe 'negative lookahead' do
    it "influences the error tree" do
      parser = str('f').absent? >> str('b')
      cause = catch_failed_parse { parser.parse('f') }
      
      cause.ascii_tree.should == "Failed to match sequence (!'f' 'b') at line 1 char 1.\n`- Input should not start with 'f' at line 1 char 1.\n"
    end 
  end
  describe 'positive lookahead' do
    it "influences the error tree" do
      parser = str('f').present? >> str('b')
      cause = catch_failed_parse { parser.parse('b') }
      
      cause.ascii_tree.should == "Failed to match sequence (&'f' 'b') at line 1 char 1.\n`- Input should start with 'f' at line 1 char 1.\n"
    end 
  end
end