File: errors_spec.rb

package info (click to toggle)
ruby-regexp-parser 2.11.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,092 kB
  • sloc: ruby: 6,891; makefile: 6; sh: 3
file content (32 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe('Parsing errors') do
  let(:parser) { Regexp::Parser.new }
  before { parser.parse(/foo/) } # initializes ivars

  it('raises UnknownTokenTypeError for unknown token types') do
    expect { parser.send(:parse_token, Regexp::Token.new(:foo, :bar)) }
      .to raise_error(Regexp::Parser::UnknownTokenTypeError)
  end

  RSpec.shared_examples 'UnknownTokenError' do |type|
    it "raises for unknown tokens of type #{type}" do
      expect { parser.send(:parse_token, Regexp::Token.new(type, :foo)) }
        .to raise_error(Regexp::Parser::UnknownTokenError)
    end
  end

  include_examples 'UnknownTokenError', :anchor
  include_examples 'UnknownTokenError', :backref
  include_examples 'UnknownTokenError', :conditional
  include_examples 'UnknownTokenError', :free_space
  include_examples 'UnknownTokenError', :group
  include_examples 'UnknownTokenError', :meta
  include_examples 'UnknownTokenError', :nonproperty
  include_examples 'UnknownTokenError', :property
  include_examples 'UnknownTokenError', :quantifier
  include_examples 'UnknownTokenError', :set
  include_examples 'UnknownTokenError', :type
end