Sha256: 59093be90ad74926e0f46a2d8fdb9e0e24f4fa568a3f373b8d0f0f614d664dbc

Contents?: true

Size: 940 Bytes

Versions: 10

Compression:

Stored size: 940 Bytes

Contents

describe "String#tr" do
  it "replaces occurances of character with substitute" do
    # identity checks (no substitution)
    'abc'.tr('', 'z').should == 'abc'
    'abc'.tr('a', 'a').should == 'abc'
    'abc'.tr('a', 'az').should == 'abc'

    # single char substitutions
    'a'.tr('a', 'b').should == 'b'
    'aa'.tr('a', 'b').should == 'bb'
    'abc'.tr('b', 'z').should == 'azc'
    'hello'.tr('e', 'ip').should == 'hillo'

    # multiple char substitutions
    'hello'.tr('el', 'ip').should == 'hippo'
    'hello'.tr('aeiou', '*').should == 'h*ll*'

    # inverted substitutions
    'hello'.tr('^aeiou', '*').should == '*e**o'

    # range substitutions
    'abc'.tr('a-c', '*').should == '***'
    'hello'.tr('e-lo', 'ab').should == 'babbb'
    'hello'.tr('a-y', 'b-z').should == 'ifmmp'

    # truncation
    'abcd'.tr('a', '').should == 'bcd'
    'abcd'.tr('abc', '').should == 'd'
    'abcd'.tr('b-d', '').should == 'a'
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
opal-0.5.5 spec/opal/core/string/tr_spec.rb
opal-0.5.4 spec/corelib/string/tr_spec.rb
opal-0.5.2 spec/corelib/string/tr_spec.rb
opal-0.5.0 spec/corelib/string/tr_spec.rb
opal-0.4.4 spec/rubyspec/core/string/tr_spec.rb
opal-0.4.3 spec/rubyspec/core/string/tr_spec.rb
opal-0.4.2 spec/rubyspec/core/string/tr_spec.rb
opal-0.4.1 spec/rubyspec/core/string/tr_spec.rb
opal-0.4.0 spec/rubyspec/core/string/tr_spec.rb
opal-0.3.44 spec/rubyspec/core/string/tr_spec.rb