diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/io/lineno_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) | |
download | ruby-1d15d5f08032acf1b7bceacbb450d617ff6e0931.tar.gz |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/io/lineno_spec.rb')
-rw-r--r-- | spec/ruby/core/io/lineno_spec.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/ruby/core/io/lineno_spec.rb b/spec/ruby/core/io/lineno_spec.rb new file mode 100644 index 0000000000..4fddbf135c --- /dev/null +++ b/spec/ruby/core/io/lineno_spec.rb @@ -0,0 +1,95 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) + +describe "IO#lineno" do + before :each do + @io = IOSpecs.io_fixture "lines.txt" + end + + after :each do + @io.close if @io + end + + it "raises an IOError on a closed stream" do + lambda { IOSpecs.closed_io.lineno }.should raise_error(IOError) + end + + it "returns the current line number" do + @io.lineno.should == 0 + + count = 0 + while @io.gets + @io.lineno.should == count += 1 + end + + @io.rewind + @io.lineno.should == 0 + end +end + +describe "IO#lineno=" do + before :each do + @io = IOSpecs.io_fixture "lines.txt" + end + + after :each do + @io.close if @io + end + + it "raises an IOError on a closed stream" do + lambda { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError) + end + + it "calls #to_int on a non-numeric argument" do + obj = mock('123') + obj.should_receive(:to_int).and_return(123) + + @io.lineno = obj + @io.lineno.should == 123 + end + + it "truncates a Float argument" do + @io.lineno = 1.5 + @io.lineno.should == 1 + + @io.lineno = 92233.72036854775808 + @io.lineno.should == 92233 + end + + it "raises TypeError on nil argument" do + lambda { @io.lineno = nil }.should raise_error(TypeError) + end + + it "sets the current line number to the given value" do + @io.lineno = count = 500 + + while @io.gets + @io.lineno.should == count += 1 + end + + @io.rewind + @io.lineno.should == 0 + end + + it "does not change $." do + original_line = $. + numbers = [-2**30, -2**16, -2**8, -100, -10, -1, 0, 1, 10, 2**8, 2**16, 2**30] + numbers.each do |num| + @io.lineno = num + @io.lineno.should == num + $..should == original_line + end + end + + it "does not change $. until next read" do + $. = 0 + $..should == 0 + + @io.lineno = count = 500 + $..should == 0 + + while @io.gets + $..should == count += 1 + end + end +end |