Sha256: 477620f3a29f2ba19743fdb808ddf0565ab54fb8d010190b243cab11ded91be2

Contents?: true

Size: 905 Bytes

Versions: 10

Compression:

Stored size: 905 Bytes

Contents

require 'spec_helper'

describe 'String' do
  describe '#gsub' do
    it 'handles recursive gsub' do
      pass_slot_rx = /{(\d+)}/
      recurse_gsub = -> text {
        text.gsub(pass_slot_rx) {
          index = $1.to_i
          if index == 0
            recurse_gsub.call '{1}'
          else
            'value'
          end
        }
      }
      result = recurse_gsub.call '<code>{0}</code>'
      result.should == '<code>value</code>'
    end

    it 'works well with zero-length matches' do
      expect("test".gsub(/^/, '2')).to eq "2test"
      expect("test".gsub(/$/, '2')).to eq "test2"
      expect("test".gsub(/\b/, '2')).to eq "2test2"
    end
  end

  describe '#sub' do
    it 'works well with zero-length matches' do
      expect("test".sub(/^/, '2')).to eq "2test"
      expect("test".sub(/$/, '2')).to eq "test2"
      expect("test".sub(/\b/, '2')).to eq "2test"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
opal-1.3.1 spec/opal/core/string/gsub_spec.rb
opal-1.3.0 spec/opal/core/string/gsub_spec.rb
opal-1.3.0.rc1 spec/opal/core/string/gsub_spec.rb
opal-1.3.0.alpha1 spec/opal/core/string/gsub_spec.rb
opal-1.2.0 spec/opal/core/string/gsub_spec.rb
opal-1.2.0.beta1 spec/opal/core/string/gsub_spec.rb
opal-1.1.1 spec/opal/core/string/gsub_spec.rb
opal-1.1.1.rc1 spec/opal/core/string/gsub_spec.rb
opal-1.1.0 spec/opal/core/string/gsub_spec.rb
opal-1.1.0.rc1 spec/opal/core/string/gsub_spec.rb