Sha256: 544e7170729aae15f8ad05a59fd3c041f0a3a70dc31c8e0ee0b2a0a6c693b7ba

Contents?: true

Size: 1.11 KB

Versions: 52

Compression:

Stored size: 1.11 KB

Contents

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

with_feature :encoding do
  describe "String#chr" do
    it "returns a copy of self" do
      s = 'e'
      s.object_id.should_not == s.chr.object_id
    end

    it "returns a String" do
      'glark'.chr.should be_an_instance_of(String)
    end

    it "returns an empty String if self is an empty String" do
      "".chr.should == ""
    end

    it "returns a 1-character String" do
      "glark".chr.size.should == 1
    end

    it "returns the character at the start of the String" do
      "Goodbye, world".chr.should == "G"
    end

    it "returns a String in the same encoding as self" do
      "\x24".encode(Encoding::US_ASCII).chr.encoding.should == Encoding::US_ASCII
    end

    it "understands multi-byte characters" do
      s = "\u{9879}"
      s.bytesize.should == 3
      s.chr.should == s
    end

    it "understands Strings that contain a mixture of character widths" do
      three = "\u{8082}"
      three.bytesize.should == 3
      four = "\u{77082}"
      four.bytesize.should == 4
      "#{three}#{four}".chr.should == three
    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/chr_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/string/chr_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/string/chr_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/string/chr_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/string/chr_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/string/chr_spec.rb