diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | a3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/core/io/seek_spec.rb | |
parent | 52df1d0d3370919711c0577aaa42d1a864709885 (diff) | |
download | ruby-a3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5.tar.gz |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/core/io/seek_spec.rb')
-rw-r--r-- | spec/rubyspec/core/io/seek_spec.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/rubyspec/core/io/seek_spec.rb b/spec/rubyspec/core/io/seek_spec.rb new file mode 100644 index 0000000000..f7e138cbe9 --- /dev/null +++ b/spec/rubyspec/core/io/seek_spec.rb @@ -0,0 +1,79 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) +require File.expand_path('../shared/pos', __FILE__) + +describe "IO#seek" do + it_behaves_like :io_set_pos, :seek +end + +describe "IO#seek" do + before :each do + @io = IOSpecs.io_fixture "lines.txt" + end + + after :each do + @io.close unless @io.closed? + end + + it "moves the read position relative to the current position with SEEK_CUR" do + lambda { @io.seek(-1) }.should raise_error(Errno::EINVAL) + @io.seek(10, IO::SEEK_CUR) + @io.readline.should == "igne une.\n" + @io.seek(-5, IO::SEEK_CUR) + @io.readline.should == "une.\n" + end + + it "moves the read position relative to the start with SEEK_SET" do + @io.seek(1) + @io.pos.should == 1 + @io.rewind + @io.seek(43, IO::SEEK_SET) + @io.readline.should == "Aquí está la línea tres.\n" + @io.seek(5, IO::SEEK_SET) + @io.readline.should == " la ligne une.\n" + end + + it "moves the read position relative to the end with SEEK_END" do + @io.seek(0, IO::SEEK_END) + @io.tell.should == 137 + @io.seek(-25, IO::SEEK_END) + @io.readline.should == "cinco.\n" + end + + it "moves the read position and clears EOF with SEEK_SET" do + value = @io.read + @io.seek(0, IO::SEEK_SET) + @io.eof?.should == false + value.should == @io.read + end + + it "moves the read position and clears EOF with SEEK_CUR" do + value = @io.read + @io.seek(-1, IO::SEEK_CUR) + @io.eof?.should == false + value[-1].should == @io.read[0] + end + + it "moves the read position and clears EOF with SEEK_END" do + value = @io.read + @io.seek(-1, IO::SEEK_END) + @io.eof?.should == false + value[-1].should == @io.read[0] + end + + platform_is :darwin do + it "supports seek offsets greater than 2^32" do + begin + zero = File.open('/dev/zero') + offset = 2**33 + zero.seek(offset, File::SEEK_SET) + pos = zero.pos + + pos.should == offset + ensure + zero.close rescue nil + end + end + end +end |