diff options
author | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-06-26 14:50:14 +0200 |
commit | d3d5ef0cca160fca538c7f556c5a6e08df5847e6 (patch) | |
tree | 57358b4b9cdd6f429d0383005ac393cb74dd3bff /spec/ruby/library/stringio | |
parent | f616e816372d14e605879d2e43c7fbdda29ef837 (diff) |
Update to ruby/spec@ab32a1a
Diffstat (limited to 'spec/ruby/library/stringio')
-rw-r--r-- | spec/ruby/library/stringio/each_line_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/library/stringio/each_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/library/stringio/gets_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/library/stringio/readline_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/library/stringio/readlines_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/library/stringio/shared/each.rb | 37 |
6 files changed, 91 insertions, 0 deletions
diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb index 1389408399..c68f7dae82 100644 --- a/spec/ruby/library/stringio/each_line_spec.rb +++ b/spec/ruby/library/stringio/each_line_spec.rb @@ -17,3 +17,7 @@ end describe "StringIO#each_line when passed chomp" do it_behaves_like :stringio_each_chomp, :each_line end + +describe "StringIO#each_line when passed limit" do + it_behaves_like :stringio_each_limit, :each_line +end diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb index a76460049b..2c30ed5cda 100644 --- a/spec/ruby/library/stringio/each_spec.rb +++ b/spec/ruby/library/stringio/each_spec.rb @@ -17,3 +17,11 @@ end describe "StringIO#each when passed chomp" do it_behaves_like :stringio_each_chomp, :each end + +describe "StringIO#each when passed chomp" do + it_behaves_like :stringio_each_separator_and_chomp, :each +end + +describe "StringIO#each when passed limit" do + it_behaves_like :stringio_each_limit, :each +end diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb index 97429e6a29..d597ec0e45 100644 --- a/spec/ruby/library/stringio/gets_spec.rb +++ b/spec/ruby/library/stringio/gets_spec.rb @@ -171,6 +171,10 @@ describe "StringIO#gets when passed [limit]" do it "returns a blank string when passed a limit of 0" do @io.gets(0).should == "" end + + it "ignores it when passed a negative limit" do + @io.gets(-4).should == "this>is>an>example" + end end describe "StringIO#gets when passed [separator] and [limit]" do diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb index 94b67bc92d..b794e5fade 100644 --- a/spec/ruby/library/stringio/readline_spec.rb +++ b/spec/ruby/library/stringio/readline_spec.rb @@ -128,3 +128,23 @@ describe "StringIO#readline when passed [chomp]" do io.readline(chomp: true).should == "this>is>an>example" end end + +describe "StringIO#readline when passed [limit]" do + before :each do + @io = StringIO.new("this>is>an>example") + end + + it "returns the data read until the limit is met" do + io = StringIO.new("this>is>an>example\n") + io.readline(3).should == "thi" + end + + it "returns a blank string when passed a limit of 0" do + @io.readline(0).should == "" + end + + it "ignores it when the limit is negative" do + seen = [] + @io.readline(-4).should == "this>is>an>example" + end +end diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb index 4b007787e2..c471d0fd73 100644 --- a/spec/ruby/library/stringio/readlines_spec.rb +++ b/spec/ruby/library/stringio/readlines_spec.rb @@ -98,3 +98,21 @@ describe "StringIO#readlines when passed [chomp]" do io.readlines(chomp: true).should == ["this>is", "an>example"] end end + +describe "StringIO#readlines when passed [limit]" do + before :each do + @io = StringIO.new("a b c d e\n1 2 3 4 5") + end + + it "returns the data read until the limit is met" do + @io.readlines(4).should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] + end + + it "raises ArgumentError when limit is 0" do + -> { @io.readlines(0) }.should raise_error(ArgumentError) + end + + it "ignores it when the limit is negative" do + @io.readlines(-4).should == ["a b c d e\n", "1 2 3 4 5"] + end +end diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb index 3be6661ce5..bf3265ee46 100644 --- a/spec/ruby/library/stringio/shared/each.rb +++ b/spec/ruby/library/stringio/shared/each.rb @@ -123,4 +123,41 @@ describe :stringio_each_chomp, shared: true do io.send(@method, chomp: true) {|s| seen << s } seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] end + + it "returns each line with removed newline characters when called without block" do + seen = [] + io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end") + enum = io.send(@method, chomp: true) + enum.each {|s| seen << s } + seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"] + end +end + +describe :stringio_each_separator_and_chomp, shared: true do + it "yields each line with removed separator to the passed block" do + seen = [] + io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + io.send(@method, "|", chomp: true) {|s| seen << s } + seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] + end + + it "returns each line with removed separator when called without block" do + seen = [] + io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end") + enum = io.send(@method, "|", chomp: true) + enum.each {|s| seen << s } + seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"] + end +end + +describe :stringio_each_limit, shared: true do + before :each do + @io = StringIO.new("a b c d e\n1 2 3 4 5") + end + + it "returns the data read until the limit is met" do + seen = [] + @io.send(@method, 4) { |s| seen << s } + seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"] + end end |