summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/io')
-rw-r--r--spec/ruby/core/io/binmode_spec.rb4
-rw-r--r--spec/ruby/core/io/dup_spec.rb19
-rw-r--r--spec/ruby/core/io/external_encoding_spec.rb5
-rw-r--r--spec/ruby/core/io/internal_encoding_spec.rb5
-rw-r--r--spec/ruby/core/io/lineno_spec.rb36
-rw-r--r--spec/ruby/core/io/set_encoding_by_bom_spec.rb14
-rw-r--r--spec/ruby/core/io/sysread_spec.rb5
-rw-r--r--spec/ruby/core/io/sysseek_spec.rb5
8 files changed, 93 insertions, 0 deletions
diff --git a/spec/ruby/core/io/binmode_spec.rb b/spec/ruby/core/io/binmode_spec.rb
index b698777cad..342cac2a9b 100644
--- a/spec/ruby/core/io/binmode_spec.rb
+++ b/spec/ruby/core/io/binmode_spec.rb
@@ -57,4 +57,8 @@ describe "IO#binmode?" do
@duped = @file.dup
@duped.binmode?.should == @file.binmode?
end
+
+ it "raises an IOError on closed stream" do
+ -> { IOSpecs.closed_io.binmode? }.should raise_error(IOError)
+ end
end
diff --git a/spec/ruby/core/io/dup_spec.rb b/spec/ruby/core/io/dup_spec.rb
index 8cadaee118..68d538377f 100644
--- a/spec/ruby/core/io/dup_spec.rb
+++ b/spec/ruby/core/io/dup_spec.rb
@@ -84,4 +84,23 @@ end
dup.close
end
end
+
+ it "always sets the autoclose flag for the new IO object" do
+ @f.autoclose = true
+ dup = @f.dup
+ begin
+ dup.should.autoclose?
+ ensure
+ dup.close
+ end
+
+ @f.autoclose = false
+ dup = @f.dup
+ begin
+ dup.should.autoclose?
+ ensure
+ dup.close
+ @f.autoclose = true
+ end
+ end
end
diff --git a/spec/ruby/core/io/external_encoding_spec.rb b/spec/ruby/core/io/external_encoding_spec.rb
index 9666974647..c1b727d930 100644
--- a/spec/ruby/core/io/external_encoding_spec.rb
+++ b/spec/ruby/core/io/external_encoding_spec.rb
@@ -1,4 +1,5 @@
require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :io_external_encoding_write, shared: true do
describe "when Encoding.default_internal is nil" do
@@ -93,6 +94,10 @@ describe "IO#external_encoding" do
rm_r @name
end
+ it "raises an IOError on closed stream" do
+ -> { IOSpecs.closed_io.external_encoding }.should raise_error(IOError)
+ end
+
describe "with 'r' mode" do
describe "when Encoding.default_internal is nil" do
before :each do
diff --git a/spec/ruby/core/io/internal_encoding_spec.rb b/spec/ruby/core/io/internal_encoding_spec.rb
index 10ebf28707..210e969c7b 100644
--- a/spec/ruby/core/io/internal_encoding_spec.rb
+++ b/spec/ruby/core/io/internal_encoding_spec.rb
@@ -1,4 +1,5 @@
require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :io_internal_encoding, shared: true do
describe "when Encoding.default_internal is not set" do
@@ -112,6 +113,10 @@ describe "IO#internal_encoding" do
Encoding.default_internal = @internal
end
+ it "raises an IOError on closed stream" do
+ -> { IOSpecs.closed_io.internal_encoding }.should raise_error(IOError)
+ end
+
describe "with 'r' mode" do
it_behaves_like :io_internal_encoding, nil, "r"
end
diff --git a/spec/ruby/core/io/lineno_spec.rb b/spec/ruby/core/io/lineno_spec.rb
index 3d1b2275cc..99266ecca1 100644
--- a/spec/ruby/core/io/lineno_spec.rb
+++ b/spec/ruby/core/io/lineno_spec.rb
@@ -14,6 +14,24 @@ describe "IO#lineno" do
-> { IOSpecs.closed_io.lineno }.should raise_error(IOError)
end
+ it "raises an IOError on a write-only stream" do
+ name = tmp("io_lineno.txt")
+ begin
+ File.open(name, 'w') do |f|
+ -> { f.lineno }.should raise_error(IOError)
+ end
+ ensure
+ rm_r name
+ end
+ end
+
+ it "raises an IOError on a duplexed stream with the read side closed" do
+ IO.popen('cat', 'r+') do |p|
+ p.close_read
+ -> { p.lineno }.should raise_error(IOError)
+ end
+ end
+
it "returns the current line number" do
@io.lineno.should == 0
@@ -40,6 +58,24 @@ describe "IO#lineno=" do
-> { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError)
end
+ it "raises an IOError on a write-only stream" do
+ name = tmp("io_lineno.txt")
+ begin
+ File.open(name, 'w') do |f|
+ -> { f.lineno = 0 }.should raise_error(IOError)
+ end
+ ensure
+ rm_r name
+ end
+ end
+
+ it "raises an IOError on a duplexed stream with the read side closed" do
+ IO.popen('cat', 'r+') do |p|
+ p.close_read
+ -> { p.lineno = 0 }.should raise_error(IOError)
+ end
+ end
+
it "calls #to_int on a non-numeric argument" do
obj = mock('123')
obj.should_receive(:to_int).and_return(123)
diff --git a/spec/ruby/core/io/set_encoding_by_bom_spec.rb b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
index b8e4eedcb9..c551042bee 100644
--- a/spec/ruby/core/io/set_encoding_by_bom_spec.rb
+++ b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
@@ -34,6 +34,20 @@ describe "IO#set_encoding_by_bom" do
@io.external_encoding.should == Encoding::UTF_16BE
end
+ it "returns the result encoding if found BOM UTF_32LE sequence" do
+ File.binwrite(@name, "\xFF\xFE\x00\x00abc")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32LE
+ @io.external_encoding.should == Encoding::UTF_32LE
+ end
+
+ it "returns the result encoding if found BOM UTF_32BE sequence" do
+ File.binwrite(@name, "\x00\x00\xFE\xFFabc")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32BE
+ @io.external_encoding.should == Encoding::UTF_32BE
+ end
+
it "returns nil if found BOM sequence not provided" do
File.write(@name, "abc")
diff --git a/spec/ruby/core/io/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb
index 024200efea..8201ad47ca 100644
--- a/spec/ruby/core/io/sysread_spec.rb
+++ b/spec/ruby/core/io/sysread_spec.rb
@@ -50,6 +50,11 @@ describe "IO#sysread on a file" do
@file.sysread(5).should == "56789"
end
+ it "raises an error when called after buffered reads" do
+ @file.readline
+ -> { @file.sysread(5) }.should raise_error(IOError)
+ end
+
it "reads normally even when called immediately after a buffered IO#read" do
@file.read(15)
@file.sysread(5).should == "56789"
diff --git a/spec/ruby/core/io/sysseek_spec.rb b/spec/ruby/core/io/sysseek_spec.rb
index df894734e3..e631939bce 100644
--- a/spec/ruby/core/io/sysseek_spec.rb
+++ b/spec/ruby/core/io/sysseek_spec.rb
@@ -26,6 +26,11 @@ describe "IO#sysseek" do
-> { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError)
end
+ it "seeks normally even when called immediately after a buffered IO#read" do
+ @io.read(15)
+ @io.sysseek(-5, IO::SEEK_CUR).should == 10
+ end
+
it "moves the read position relative to the start with SEEK_SET" do
@io.sysseek(43, IO::SEEK_SET)
@io.readline.should == "Aquí está la línea tres.\n"