Sha256: 8ac17e7f29cde24803c2af8b031017f42df6abd9b5fbdc9f12bfca3966803d0d

Contents?: true

Size: 1.16 KB

Versions: 59

Compression:

Stored size: 1.16 KB

Contents

# -*- encoding: utf-8 -*-
describe :stringio_codepoints, :shared => true do
  before(:each) do
    @io = StringIO.new("∂φ/∂x = gaîté")
    @enum = @io.send(@method)
  end

  it "returns an Enumerator" do
    @enum.should be_an_instance_of(enumerator_class)
  end

  it "yields each codepoint code in turn" do
    @enum.to_a.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
  end

  it "yields each codepoint starting from the current position" do
    @io.pos = 15
    @enum.to_a.should == [238, 116, 233]
  end

  it "raises an error if reading invalid sequence" do
    @io.pos = 1  # inside of a multibyte sequence
    lambda { @enum.first }.should raise_error(ArgumentError)
  end

  it "raises an IOError if not readable" do
    @io.close_read
    lambda { @enum.to_a }.should raise_error(IOError)

    io = StringIO.new("xyz", "w")
    lambda { io.send(@method).to_a }.should raise_error(IOError)
  end


  it "calls the given block" do
    r  = []
    @io.send(@method){|c| r << c }
    r.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
  end

  it "returns self" do
    @io.send(@method) {|l| l }.should equal(@io)
  end

end

Version data entries

59 entries across 59 versions & 3 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-7.5.1 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-7.4.1 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-7.1.17 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-6.2.0 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rubysl-stringio-2.3 spec/shared/codepoints.rb
rhodes-6.0.11 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rubysl-stringio-2.2 spec/shared/codepoints.rb
rubysl-stringio-2.1 spec/shared/codepoints.rb
rhodes-5.5.18 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.17 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.15 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.2 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rhodes-5.5.0 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb
rubysl-stringio-2.1.0 spec/shared/codepoints.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/library/stringio/shared/codepoints.rb