Sha256: 78699c6ba8829175957d513d744a3efdd0a10e7f3ec5de688b6d83425d3c2911

Contents?: true

Size: 986 Bytes

Versions: 36

Compression:

Stored size: 986 Bytes

Contents

require 'spec_helper'

RSpec.describe('passing options to scan') do
  def expect_type_tokens(tokens, type_tokens)
    expect(tokens.map { |type, token, *| [type, token] }).to eq(type_tokens)
  end

  it 'raises if if scanning from a Regexp and options are passed' do
    expect { RS.scan(/a+/, options: ::Regexp::EXTENDED) }.to raise_error(
      ArgumentError,
      'options cannot be supplied unless scanning a String'
    )
  end

  it 'sets free_spacing based on options if scanning from a String' do
    expect_type_tokens(
      RS.scan('a+#c', options: ::Regexp::MULTILINE | ::Regexp::EXTENDED),
      [
        %i[literal literal],
        %i[quantifier one_or_more],
        %i[free_space comment]
      ]
    )
  end

  it 'does not set free_spacing if scanning from a String and passing no options' do
    expect_type_tokens(
      RS.scan('a+#c'),
      [
        %i[literal literal],
        %i[quantifier one_or_more],
        %i[literal literal]
      ]
    )
  end
end

Version data entries

36 entries across 26 versions & 7 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/regexp_parser-2.2.0/spec/scanner/options_spec.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
regexp_parser-2.2.0 spec/scanner/options_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/regexp_parser-1.8.0/spec/scanner/options_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/spec/scanner/options_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/spec/scanner/options_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/scanner/options_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/scanner/options_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/scanner/options_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/scanner/options_spec.rb