Sha256: 837b7aadd59ffcad78246def8c549bb1882a40bf4417553a0bebb059c8f9952f

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

# backtick_javascript: true

describe 'Regexp#match' do
  describe 'when pos is not specified' do
    it 'calls .exec only once on the current object' do
      regexp = /test/
      calls = 0
      %x(
        regexp._exec = regexp.exec;
        regexp.exec = function(str) {
          var match = this._exec(str);
          calls++;
          return match;
        }
      )
      result = regexp.match('test test')
      calls.should == 1
      result.begin(0).should == 0
      result[0].should == 'test'
    end
  end

  describe 'when pos is specified' do
    it 'does not call .exec on the current object' do
      regexp = /test/
      calls = 0
      %x(
        regexp._exec = regexp.exec;
        regexp.exec = function(str) {
          var match = this._exec(str);
          calls++;
          return match;
        }
      )
      result = regexp.match('test test', 1)
      calls.should == 0
      result[0].should == 'test'
      result.begin(0).should == 5
    end
  end
end

describe 'Regexp#match?' do
  describe 'when pos is not specified' do
    it 'calls .test on the current object' do
      regexp = /test/
      calls = 0
      %x(
        regexp._test = regexp.test;
        regexp.test = function(str) {
          var verdict = this._test(str);
          calls++;
          return verdict;
        }
      )
      result = regexp.match?('test test')
      calls.should == 1
      result.should == true
    end
  end

  describe 'when pos is specified' do
    it 'does not call .test on the current object' do
      regexp = /test/
      calls = 0
      %x(
        regexp._test = regexp.test;
        regexp.test = function(str) {
          var verdict = this._test(str);
          calls++;
          return verdict;
        }
      )
      result = regexp.match?('test test', 1)
      calls.should == 0
      # FIXME pos is not yet supported by Opal's Regexp#match?
      #result.should == true
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/core/regexp/match_spec.rb
opal-1.8.2 spec/opal/core/regexp/match_spec.rb
opal-1.8.1 spec/opal/core/regexp/match_spec.rb
opal-1.8.0 spec/opal/core/regexp/match_spec.rb
opal-1.8.0.beta1 spec/opal/core/regexp/match_spec.rb
opal-1.8.0.alpha1 spec/opal/core/regexp/match_spec.rb