Sha256: aaca57974c3031b20c14d631f21f5fd4ff27eb688fd21da83e5f9b1054f7331d

Contents?: true

Size: 1.23 KB

Versions: 32

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

RSpec.describe(Regexp::Expression::Subexpression) do
  specify('#ts, #te') do
    regx = /abcd|ghij|klmn|pqur/
    root = RP.parse(regx)

    alt = root.first

    { 0 => [0, 4], 1 => [5, 9], 2 => [10, 14], 3 => [15, 19] }.each do |index, span|
      sequence = alt[index]

      expect(sequence.ts).to eq span[0]
      expect(sequence.te).to eq span[1]
    end
  end

  specify('#nesting_level') do
    root = RP.parse(/a(b(\d|[ef-g[h]]))/)

    tests = {
      'a'            => 1,
      'b'            => 2,
      '\d|[ef-g[h]]' => 3, # alternation
      '\d'           => 4, # first alternative
      '[ef-g[h]]'    => 4, # second alternative
      'e'            => 5,
      'f-g'          => 5,
      'f'            => 6,
      'g'            => 6,
      'h'            => 6,
    }

    root.each_expression do |exp|
      next unless expected_nesting_level = tests.delete(exp.to_s)
      expect(expected_nesting_level).to eq exp.nesting_level
    end

    expect(tests).to be_empty
  end

  specify('#dig') do
    root = RP.parse(/(((a)))/)

    expect(root.dig(0).to_s).to eq '(((a)))'
    expect(root.dig(0, 0, 0, 0).to_s).to eq 'a'
    expect(root.dig(0, 0, 0, 0, 0)).to be_nil
    expect(root.dig(3, 7)).to be_nil
  end
end

Version data entries

32 entries across 27 versions & 6 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/expression/subexpression_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/regexp_parser-1.8.2/spec/expression/subexpression_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.2/spec/expression/subexpression_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/regexp_parser-1.8.2/spec/expression/subexpression_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.2/spec/expression/subexpression_spec.rb
regexp_parser-2.0.1 spec/expression/subexpression_spec.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/regexp_parser-1.8.2/spec/expression/subexpression_spec.rb
regexp_parser-2.0.0 spec/expression/subexpression_spec.rb
regexp_parser-1.8.2 spec/expression/subexpression_spec.rb
regexp_parser-1.8.1 spec/expression/subexpression_spec.rb
regexp_parser-1.8.0 spec/expression/subexpression_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.7.1/spec/expression/subexpression_spec.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.7.0/spec/expression/subexpression_spec.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/regexp_parser-1.7.1/spec/expression/subexpression_spec.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/regexp_parser-1.7.1/spec/expression/subexpression_spec.rb