Sha256: 05f6941bac9c8750e5152eb1393395f8bdce115ddc7102e51b3177ed643e89b3

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

RSpec.describe('Anchor parsing') do
  tests = {
    '^a'      => [0, :anchor,   :bol,                 Anchor::BOL],
    'a$'      => [1, :anchor,   :eol,                 Anchor::EOL],

    '\Aa'     => [0, :anchor,   :bos,                 Anchor::BOS],
    'a\z'     => [1, :anchor,   :eos,                 Anchor::EOS],
    'a\Z'     => [1, :anchor,   :eos_ob_eol,          Anchor::EOSobEOL],

    'a\b'     => [1, :anchor,   :word_boundary,       Anchor::WordBoundary],
    'a\B'     => [1, :anchor,   :nonword_boundary,    Anchor::NonWordBoundary],

    'a\G'     => [1, :anchor,   :match_start,         Anchor::MatchStart],

    "\\\\Aa"  => [0, :escape,   :backslash,           EscapeSequence::Literal],
  }

  tests.each_with_index do |(pattern, (index, type, token, klass)), count|
    specify("parse_anchor_#{token}_#{count}") do
      root = RP.parse(pattern, 'ruby/1.9')
      exp = root.expressions.at(index)

      expect(exp).to be_a(klass)

      expect(exp.type).to eq type
      expect(exp.token).to eq token
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regexp_parser-1.5.0 spec/parser/anchors_spec.rb