Sha256: a4710797f26189216f1126391ef45f30529d9ffa5888d26ffc5782124687e42c

Contents?: true

Size: 1.23 KB

Versions: 20

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

20 entries across 14 versions & 6 rubygems

Version Path
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/regexp_parser-2.2.0/spec/expression/subexpression_spec.rb
regexp_parser-2.2.0 spec/expression/subexpression_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/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-2.0.3/spec/expression/subexpression_spec.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.0.3/spec/expression/subexpression_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/expression/subexpression_spec.rb
regexp_parser-2.1.1 spec/expression/subexpression_spec.rb
regexp_parser-2.1.0 spec/expression/subexpression_spec.rb
regexp_parser-2.0.3 spec/expression/subexpression_spec.rb
regexp_parser-2.0.2 spec/expression/subexpression_spec.rb