rubysl-stringio 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rubysl/stringio.rb +2 -0
- data/lib/rubysl/stringio/stringio.rb +611 -0
- data/lib/rubysl/stringio/version.rb +5 -0
- data/lib/stringio.rb +1 -0
- data/rubysl-stringio.gemspec +24 -0
- data/spec/append_spec.rb +83 -0
- data/spec/binmode_spec.rb +8 -0
- data/spec/bytes_spec.rb +12 -0
- data/spec/chars_spec.rb +12 -0
- data/spec/close_read_spec.rb +30 -0
- data/spec/close_spec.rb +22 -0
- data/spec/close_write_spec.rb +30 -0
- data/spec/closed_read_spec.rb +11 -0
- data/spec/closed_spec.rb +15 -0
- data/spec/closed_write_spec.rb +11 -0
- data/spec/codepoints_spec.rb +11 -0
- data/spec/each_byte_spec.rb +10 -0
- data/spec/each_char_spec.rb +12 -0
- data/spec/each_codepoint_spec.rb +12 -0
- data/spec/each_line_spec.rb +14 -0
- data/spec/each_spec.rb +14 -0
- data/spec/eof_spec.rb +10 -0
- data/spec/external_encoding_spec.rb +12 -0
- data/spec/fcntl_spec.rb +7 -0
- data/spec/fileno_spec.rb +8 -0
- data/spec/fixtures/classes.rb +15 -0
- data/spec/flush_spec.rb +8 -0
- data/spec/fsync_spec.rb +8 -0
- data/spec/getbyte_spec.rb +25 -0
- data/spec/getc_spec.rb +31 -0
- data/spec/gets_spec.rb +245 -0
- data/spec/initialize_copy_spec.rb +95 -0
- data/spec/initialize_spec.rb +193 -0
- data/spec/internal_encoding_spec.rb +12 -0
- data/spec/isatty_spec.rb +6 -0
- data/spec/length_spec.rb +6 -0
- data/spec/lineno_spec.rb +29 -0
- data/spec/lines_spec.rb +16 -0
- data/spec/open_spec.rb +215 -0
- data/spec/path_spec.rb +15 -0
- data/spec/pid_spec.rb +7 -0
- data/spec/pos_spec.rb +27 -0
- data/spec/print_spec.rb +113 -0
- data/spec/printf_spec.rb +60 -0
- data/spec/putc_spec.rb +105 -0
- data/spec/puts_spec.rb +173 -0
- data/spec/read_nonblock_spec.rb +29 -0
- data/spec/read_spec.rb +62 -0
- data/spec/readbyte_spec.rb +21 -0
- data/spec/readchar_spec.rb +19 -0
- data/spec/readline_spec.rb +127 -0
- data/spec/readlines_spec.rb +124 -0
- data/spec/readpartial_spec.rb +29 -0
- data/spec/reopen_spec.rb +303 -0
- data/spec/rewind_spec.rb +23 -0
- data/spec/seek_spec.rb +75 -0
- data/spec/set_encoding_spec.rb +34 -0
- data/spec/shared/codepoints.rb +45 -0
- data/spec/shared/each.rb +162 -0
- data/spec/shared/each_byte.rb +60 -0
- data/spec/shared/each_char.rb +50 -0
- data/spec/shared/eof.rb +24 -0
- data/spec/shared/getc.rb +43 -0
- data/spec/shared/isatty.rb +5 -0
- data/spec/shared/length.rb +12 -0
- data/spec/shared/read.rb +186 -0
- data/spec/shared/readchar.rb +29 -0
- data/spec/shared/sysread.rb +27 -0
- data/spec/shared/tell.rb +12 -0
- data/spec/shared/write.rb +134 -0
- data/spec/size_spec.rb +6 -0
- data/spec/string_spec.rb +49 -0
- data/spec/stringio_spec.rb +8 -0
- data/spec/sync_spec.rb +18 -0
- data/spec/sysread_spec.rb +27 -0
- data/spec/syswrite_spec.rb +18 -0
- data/spec/tell_spec.rb +6 -0
- data/spec/truncate_spec.rb +69 -0
- data/spec/tty_spec.rb +6 -0
- data/spec/ungetbyte_spec.rb +88 -0
- data/spec/ungetc_spec.rb +98 -0
- data/spec/write_nonblock_spec.rb +20 -0
- data/spec/write_spec.rb +18 -0
- metadata +267 -0
data/lib/stringio.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/stringio"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/stringio/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-stringio"
|
6
|
+
spec.version = RubySL::StringIO::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library stringio.}
|
10
|
+
spec.summary = %q{Ruby standard library stringio.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-stringio"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "redcard", "~> 1.0"
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
24
|
+
end
|
data/spec/append_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#<< when passed [Object]" do
|
4
|
+
before(:each) do
|
5
|
+
@io = StringIO.new("example")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns self" do
|
9
|
+
(@io << "just testing").should equal(@io)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "writes the passed argument onto self" do
|
13
|
+
(@io << "just testing")
|
14
|
+
@io.string.should == "just testing"
|
15
|
+
(@io << " and more testing")
|
16
|
+
@io.string.should == "just testing and more testing"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "writes the passed argument at the current position" do
|
20
|
+
@io.pos = 5
|
21
|
+
@io << "<test>"
|
22
|
+
@io.string.should == "examp<test>"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "pads self with \\000 when the current position is after the end" do
|
26
|
+
@io.pos = 15
|
27
|
+
@io << "just testing"
|
28
|
+
@io.string.should == "example\000\000\000\000\000\000\000\000just testing"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "taints self's String when the passed argument is tainted" do
|
32
|
+
(@io << "test".taint)
|
33
|
+
@io.string.tainted?.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not taint self when the passed argument is tainted" do
|
37
|
+
(@io << "test".taint)
|
38
|
+
@io.tainted?.should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "updates self's position" do
|
42
|
+
@io << "test"
|
43
|
+
@io.pos.should eql(4)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "tries to convert the passed argument to a String using #to_s" do
|
47
|
+
obj = mock("to_s")
|
48
|
+
obj.should_receive(:to_s).and_return("Test")
|
49
|
+
|
50
|
+
(@io << obj).string.should == "Testple"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "StringIO#<< when self is not writable" do
|
55
|
+
it "raises an IOError" do
|
56
|
+
io = StringIO.new("test", "r")
|
57
|
+
lambda { io << "test" }.should raise_error(IOError)
|
58
|
+
|
59
|
+
io = StringIO.new("test")
|
60
|
+
io.close_write
|
61
|
+
lambda { io << "test" }.should raise_error(IOError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "StringIO#<< when in append mode" do
|
66
|
+
before(:each) do
|
67
|
+
@io = StringIO.new("example", "a")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "appends the passed argument to the end of self, ignoring current position" do
|
71
|
+
(@io << ", just testing")
|
72
|
+
@io.string.should == "example, just testing"
|
73
|
+
|
74
|
+
@io.pos = 3
|
75
|
+
(@io << " and more testing")
|
76
|
+
@io.string.should == "example, just testing and more testing"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "correctly updates self's position" do
|
80
|
+
@io << ", testing"
|
81
|
+
@io.pos.should eql(16)
|
82
|
+
end
|
83
|
+
end
|
data/spec/bytes_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require File.expand_path('../shared/each_byte', __FILE__)
|
3
|
+
|
4
|
+
ruby_version_is "1.8.7" do
|
5
|
+
describe "StringIO#bytes" do
|
6
|
+
it_behaves_like :stringio_each_byte, :bytes
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "StringIO#bytes when self is not readable" do
|
10
|
+
it_behaves_like :stringio_each_byte_not_readable, :bytes
|
11
|
+
end
|
12
|
+
end
|
data/spec/chars_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require File.expand_path('../shared/each_char', __FILE__)
|
3
|
+
|
4
|
+
ruby_version_is "1.8.7" do
|
5
|
+
describe "StringIO#chars" do
|
6
|
+
it_behaves_like :stringio_each_char, :chars
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "StringIO#chars when self is not readable" do
|
10
|
+
it_behaves_like :stringio_each_char_not_readable, :chars
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#close_read" do
|
4
|
+
before(:each) do
|
5
|
+
@io = StringIO.new("example")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns nil" do
|
9
|
+
@io.close_read.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "prevents further reading" do
|
13
|
+
@io.close_read
|
14
|
+
lambda { @io.read(1) }.should raise_error(IOError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows further writing" do
|
18
|
+
@io.close_read
|
19
|
+
@io.write("x").should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an IOError when in write-only mode" do
|
23
|
+
io = StringIO.new("example", "w")
|
24
|
+
lambda { io.close_read }.should raise_error(IOError)
|
25
|
+
|
26
|
+
io = StringIO.new("example")
|
27
|
+
io.close_read
|
28
|
+
lambda { io.close_read }.should raise_error(IOError)
|
29
|
+
end
|
30
|
+
end
|
data/spec/close_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#close" do
|
4
|
+
before(:each) do
|
5
|
+
@io = StringIOSpecs.build
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns nil" do
|
9
|
+
@io.close.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "prevents further reading and/or writing" do
|
13
|
+
@io.close
|
14
|
+
lambda { @io.read(1) }.should raise_error(IOError)
|
15
|
+
lambda { @io.write('x') }.should raise_error(IOError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an IOError when self was already closed" do
|
19
|
+
@io.close
|
20
|
+
lambda { @io.close }.should raise_error(IOError)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#close_write" do
|
4
|
+
before(:each) do
|
5
|
+
@io = StringIO.new("example")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns nil" do
|
9
|
+
@io.close_write.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "prevents further writing" do
|
13
|
+
@io.close_write
|
14
|
+
lambda { @io.write('x') }.should raise_error(IOError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows further reading" do
|
18
|
+
@io.close_write
|
19
|
+
@io.read(1).should == 'e'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an IOError when in read-only mode" do
|
23
|
+
io = StringIO.new("example", "r")
|
24
|
+
lambda { io.close_write }.should raise_error(IOError)
|
25
|
+
|
26
|
+
io = StringIO.new("example")
|
27
|
+
io.close_write
|
28
|
+
lambda { io.close_write }.should raise_error(IOError)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#closed_read?" do
|
4
|
+
it "returns true if self is not readable" do
|
5
|
+
io = StringIO.new("example", "r+")
|
6
|
+
io.close_write
|
7
|
+
io.closed_read?.should be_false
|
8
|
+
io.close_read
|
9
|
+
io.closed_read?.should be_true
|
10
|
+
end
|
11
|
+
end
|
data/spec/closed_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#closed?" do
|
4
|
+
it "returns true if self is completely closed" do
|
5
|
+
io = StringIO.new("example", "r+")
|
6
|
+
io.close_read
|
7
|
+
io.closed?.should be_false
|
8
|
+
io.close_write
|
9
|
+
io.closed?.should be_true
|
10
|
+
|
11
|
+
io = StringIO.new("example", "r+")
|
12
|
+
io.close
|
13
|
+
io.closed?.should be_true
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
|
3
|
+
describe "StringIO#closed_write?" do
|
4
|
+
it "returns true if self is not writable" do
|
5
|
+
io = StringIO.new("example", "r+")
|
6
|
+
io.close_read
|
7
|
+
io.closed_write?.should be_false
|
8
|
+
io.close_write
|
9
|
+
io.closed_write?.should be_true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
4
|
+
require File.expand_path('../shared/codepoints', __FILE__)
|
5
|
+
|
6
|
+
# See redmine #1667
|
7
|
+
describe "StringIO#codepoints" do
|
8
|
+
ruby_version_is "1.9" do
|
9
|
+
it_behaves_like(:stringio_codepoints, :codepoints)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require File.expand_path('../shared/each_byte', __FILE__)
|
3
|
+
|
4
|
+
describe "StringIO#each_byte" do
|
5
|
+
it_behaves_like :stringio_each_byte, :each_byte
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "StringIO#each_byte when self is not readable" do
|
9
|
+
it_behaves_like :stringio_each_byte_not_readable, :each_byte
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require File.expand_path('../shared/each_char', __FILE__)
|
3
|
+
|
4
|
+
ruby_version_is "1.8.7" do
|
5
|
+
describe "StringIO#each_char" do
|
6
|
+
it_behaves_like :stringio_each_char, :each_char
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "StringIO#each_char when self is not readable" do
|
10
|
+
it_behaves_like :stringio_each_char_not_readable, :chars
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
4
|
+
require File.expand_path('../shared/codepoints', __FILE__)
|
5
|
+
|
6
|
+
# See redmine #1667
|
7
|
+
describe "StringIO#each_codepoint" do
|
8
|
+
ruby_version_is "1.9" do
|
9
|
+
it_behaves_like(:stringio_codepoints, :codepoints)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
require File.expand_path('../shared/each', __FILE__)
|
3
|
+
|
4
|
+
describe "StringIO#each_line when passed a separator" do
|
5
|
+
it_behaves_like :stringio_each_separator, :each_line
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "StringIO#each_line when passed no arguments" do
|
9
|
+
it_behaves_like :stringio_each_no_arguments, :each_line
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "StringIO#each_line when self is not readable" do
|
13
|
+
it_behaves_like :stringio_each_not_readable, :each_line
|
14
|
+
end
|
data/spec/each_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
require File.expand_path('../shared/each', __FILE__)
|
3
|
+
|
4
|
+
describe "StringIO#each when passed a separator" do
|
5
|
+
it_behaves_like :stringio_each_separator, :each
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "StringIO#each when passed no arguments" do
|
9
|
+
it_behaves_like :stringio_each_no_arguments, :each
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "StringIO#each when self is not readable" do
|
13
|
+
it_behaves_like :stringio_each_not_readable, :each
|
14
|
+
end
|
data/spec/eof_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
2
|
+
require File.expand_path('../shared/eof', __FILE__)
|
3
|
+
|
4
|
+
describe "StringIO#eof?" do
|
5
|
+
it_behaves_like :stringio_eof, :eof?
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "StringIO#eof" do
|
9
|
+
it_behaves_like :stringio_eof, :eof
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
ruby_version_is "1.9.2" do
|
5
|
+
describe "StringIO#external_encoding" do
|
6
|
+
it "gets the encoding of the underlying String" do
|
7
|
+
io = StringIO.new
|
8
|
+
io.set_encoding Encoding::UTF_8
|
9
|
+
io.external_encoding.should == Encoding::UTF_8
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/fcntl_spec.rb
ADDED
data/spec/fileno_spec.rb
ADDED