Skip to content

Commit 007e23e

Browse files
nobujacob-shops
authored andcommitted
Remove tests for obsolete StringScanner methods
ruby/strscan#168
1 parent 9e3cbc7 commit 007e23e

File tree

16 files changed

+157
-293
lines changed

16 files changed

+157
-293
lines changed

spec/ruby/library/stringscanner/clear_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/ruby/library/stringscanner/empty_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/eos'
32
require 'strscan'
43

54
describe "StringScanner#eos?" do
6-
it_behaves_like :strscan_eos, :eos?
5+
before :each do
6+
@s = StringScanner.new("This is a test")
7+
end
8+
9+
it "returns true if the scan pointer is at the end of the string" do
10+
@s.terminate
11+
@s.should.eos?
12+
13+
s = StringScanner.new('')
14+
s.should.eos?
15+
end
16+
17+
it "returns false if the scan pointer is not at the end of the string" do
18+
@s.should_not.eos?
19+
end
720
end
Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,88 @@
1+
# encoding: binary
12
require_relative '../../spec_helper'
2-
require_relative 'shared/get_byte'
33
require 'strscan'
44

55
describe "StringScanner#get_byte" do
6-
it_behaves_like :strscan_get_byte, :get_byte
6+
it "scans one byte and returns it" do
7+
s = StringScanner.new('abc5.')
8+
s.get_byte.should == 'a'
9+
s.get_byte.should == 'b'
10+
s.get_byte.should == 'c'
11+
s.get_byte.should == '5'
12+
s.get_byte.should == '.'
13+
end
14+
15+
it "is not multi-byte character sensitive" do
16+
s = StringScanner.new("\244\242")
17+
s.get_byte.should == "\244"
18+
s.get_byte.should == "\242"
19+
end
20+
21+
it "returns nil at the end of the string" do
22+
# empty string case
23+
s = StringScanner.new('')
24+
s.get_byte.should == nil
25+
s.get_byte.should == nil
26+
27+
# non-empty string case
28+
s = StringScanner.new('a')
29+
s.get_byte # skip one
30+
s.get_byte.should == nil
31+
end
32+
33+
describe "#[] successive call with a capture group name" do
34+
# https://github.com/ruby/strscan/issues/139
35+
ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
36+
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
37+
it "returns nil" do
38+
s = StringScanner.new("This is a test")
39+
s.get_byte
40+
s.should.matched?
41+
s[:a].should be_nil
42+
end
43+
end
44+
end
45+
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
46+
it "raises IndexError" do
47+
s = StringScanner.new("This is a test")
48+
s.get_byte
49+
s.should.matched?
50+
-> { s[:a] }.should raise_error(IndexError)
51+
end
52+
end
53+
54+
it "returns a matching character when given Integer index" do
55+
s = StringScanner.new("This is a test")
56+
s.get_byte
57+
s[0].should == "T"
58+
end
59+
60+
# https://github.com/ruby/strscan/issues/135
61+
ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
62+
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
63+
it "ignores the previous matching with Regexp" do
64+
s = StringScanner.new("This is a test")
65+
s.exist?(/(?<a>This)/)
66+
s.should.matched?
67+
s[:a].should == "This"
68+
69+
s.get_byte
70+
s.should.matched?
71+
s[:a].should be_nil
72+
end
73+
end
74+
end
75+
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
76+
it "ignores the previous matching with Regexp" do
77+
s = StringScanner.new("This is a test")
78+
s.exist?(/(?<a>This)/)
79+
s.should.matched?
80+
s[:a].should == "This"
81+
82+
s.get_byte
83+
s.should.matched?
84+
-> { s[:a] }.should raise_error(IndexError)
85+
end
86+
end
87+
end
788
end

spec/ruby/library/stringscanner/getbyte_spec.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/peek'
32
require 'strscan'
43

54
describe "StringScanner#peek" do
6-
it_behaves_like :strscan_peek, :peek
5+
before :each do
6+
@s = StringScanner.new('This is a test')
7+
end
8+
9+
it "returns at most the specified number of bytes from the current position" do
10+
@s.peek(4).should == "This"
11+
@s.pos.should == 0
12+
@s.pos = 5
13+
@s.peek(2).should == "is"
14+
@s.peek(1000).should == "is a test"
15+
16+
s = StringScanner.new("été")
17+
s.peek(2).should == "é"
18+
end
19+
20+
it "returns an empty string when the passed argument is zero" do
21+
@s.peek(0).should == ""
22+
end
23+
24+
it "raises a ArgumentError when the passed argument is negative" do
25+
-> { @s.peek(-2) }.should raise_error(ArgumentError)
26+
end
27+
28+
it "raises a RangeError when the passed argument is a Bignum" do
29+
-> { @s.peek(bignum_value) }.should raise_error(RangeError)
30+
end
31+
32+
it "returns an instance of String when passed a String subclass" do
33+
cls = Class.new(String)
34+
sub = cls.new("abc")
35+
36+
s = StringScanner.new(sub)
37+
38+
ch = s.peek(1)
39+
ch.should_not be_kind_of(cls)
40+
ch.should be_an_instance_of(String)
41+
end
742
end

spec/ruby/library/stringscanner/peep_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/rest_size'
32
require 'strscan'
43

54
describe "StringScanner#rest_size" do
6-
it_behaves_like :strscan_rest_size, :rest_size
5+
before :each do
6+
@s = StringScanner.new('This is a test')
7+
end
8+
9+
it "returns the length of the rest of the string" do
10+
@s.rest_size.should == 14
11+
@s.scan(/This/)
12+
@s.rest_size.should == 10
13+
@s.terminate
14+
@s.rest_size.should == 0
15+
end
16+
17+
it "is equivalent to rest.size" do
18+
@s.scan(/This/)
19+
@s.rest_size.should == @s.rest.size
20+
end
721
end

spec/ruby/library/stringscanner/rest_spec.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,3 @@
2525
it_behaves_like :extract_range_matched, :rest
2626

2727
end
28-
29-
describe "StringScanner#rest?" do
30-
before :each do
31-
@s = StringScanner.new("This is a test")
32-
end
33-
34-
it "returns true if there is more data in the string" do
35-
@s.rest?.should be_true
36-
@s.scan(/This/)
37-
@s.rest?.should be_true
38-
end
39-
40-
it "returns false if there is no more data in the string" do
41-
@s.terminate
42-
@s.rest?.should be_false
43-
end
44-
45-
it "is the opposite of eos?" do
46-
@s.rest?.should_not == @s.eos?
47-
end
48-
end

spec/ruby/library/stringscanner/restsize_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)