Sha256: 02cb441de66b8e79844fc1ed207c7b3bd6a03fbb754d845cdd7cfc2acaedae0f

Contents?: true

Size: 1.45 KB

Versions: 52

Compression:

Stored size: 1.45 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.8.8" do
  describe "String#setbyte" do
    it "returns an Integer" do
      "a".setbyte(0,1).should be_kind_of(Integer)
    end

    it "modifies the receiver" do
      str = "glark"
      old_id = str.object_id
      str.setbyte(0,88)
      str.object_id.should == old_id
    end

    it "changes the byte at the given index to the new byte" do
      str = "a"
      str.setbyte(0,98)
      str.should == 'b'
    end

    it "allows changing bytes in multi-byte characters" do
      str = "\u{915}"
      str.setbyte(1,254)
      str.getbyte(1).should == 254
    end

    it "can invalidate a String's encoding" do
      str = "glark"
      str.valid_encoding?.should be_true
      str.setbyte(2,253)
      #str.valid_encoding?.should be_false
    end

    it "regards a negative index as counting from the end of the String" do
      str = "hedgehog"
      str.setbyte(-3, 108)
      str.should == "hedgelog"
    end

    it "raises an IndexError unless the index is inside the String" do
      lambda { "?".setbyte(1,97) }.should raise_error(IndexError)
    end

    it "raises a RuntimeError if self is frozen" do
      str = "cold".freeze
      str.frozen?.should be_true
      lambda { str.setbyte(3,96) }.should raise_error(RuntimeError)
    end

    it "raises a TypeError unless the second argument is an Integer" do
      lambda { "a".setbyte(0,'a') }.should raise_error(TypeError)
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/string/setbyte_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/string/setbyte_spec.rb