File: match_spec.rb

package info (click to toggle)
ruby-regexp-parser 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 6,396; sh: 12; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 681 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
require 'spec_helper'

RSpec.describe('Expression::Base#match') do
  it 'returns the #match result of the respective Regexp' do
    expect(RP.parse(/a/).match('a')[0]).to eq 'a'
  end

  it 'can be given an offset, just like Regexp#match' do
    expect(RP.parse(/./).match('ab', 1)[0]).to eq 'b'
  end

  it 'works with the #=~ alias' do
    expect(RP.parse(/a/) =~ 'a').to be_a MatchData
  end
end

RSpec.describe('Expression::Base#match?') do
  it 'returns true if the Respective Regexp matches' do
    expect(RP.parse(/a/).match?('a')).to be true
  end

  it 'returns false if the Respective Regexp does not match' do
    expect(RP.parse(/a/).match?('b')).to be false
  end
end