Sha256: 8e2e7b19bddcf21e159393eb32f5894c11455ec6449200910b407ef9194f70d0

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

# require File.dirname(__FILE__) + '/../../spec_helper'

describe "String#sub with pattern, replacement" do
  it "returns a copy of self with all occurrences of pattern replaced with replacement" do
    "hello".sub(/[aeiou]/, '*').should == "h*llo"
    "hello".sub(//, ".").should == "hello"
  end
  
  it "ignores a block if supplied" do
    "food".sub(/f/, "g") { "W" }.should == "good"
  end
  
  it "supports /i for ignoring case" do
    "Hello".sub(/h/i, "j").should == "jello"
    "hello".sub(/H/i, "j").should == "jello"
  end
end

describe "String#sub with pattern and block" do
  it "returns a copy of self with the first occurrences of pattern replaced with the block's return value" do
    # "hi".sub(/./) { |s| s + ' ' }.should == "h i"
    # "hi!".sub(/(.)(.)/) { |*a| " " }.should == '["hi"]!'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-0.3.2 gems/core/spec/core/string/sub_spec.rb
opal-0.3.1 gems/core/spec/core/string/sub_spec.rb
opal-0.3.0 gems/core/spec/core/string/sub_spec.rb