diff options
Diffstat (limited to 'spec/ruby/library/stringscanner/shared')
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/bol.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/concat.rb | 14 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/eos.rb | 17 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/extract_range.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/extract_range_matched.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/get_byte.rb | 29 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/peek.rb | 39 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/pos.rb | 11 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/rest_size.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/library/stringscanner/shared/terminate.rb | 8 |
10 files changed, 28 insertions, 132 deletions
diff --git a/spec/ruby/library/stringscanner/shared/bol.rb b/spec/ruby/library/stringscanner/shared/bol.rb index ebcdd7938f..ec5c2051b5 100644 --- a/spec/ruby/library/stringscanner/shared/bol.rb +++ b/spec/ruby/library/stringscanner/shared/bol.rb @@ -1,25 +1,25 @@ describe :strscan_bol, shared: true do it "returns true if the scan pointer is at the beginning of the line, false otherwise" do s = StringScanner.new("This is a test") - s.send(@method).should be_true + s.send(@method).should == true s.scan(/This/) - s.send(@method).should be_false + s.send(@method).should == false s.terminate - s.send(@method).should be_false + s.send(@method).should == false s = StringScanner.new("hello\nworld") - s.bol?.should be_true + s.bol?.should == true s.scan(/\w+/) - s.bol?.should be_false + s.bol?.should == false s.scan(/\n/) - s.bol?.should be_true + s.bol?.should == true s.unscan - s.bol?.should be_false + s.bol?.should == false end it "returns true if the scan pointer is at the end of the line of an empty string." do s = StringScanner.new('') s.terminate - s.send(@method).should be_true + s.send(@method).should == true end end diff --git a/spec/ruby/library/stringscanner/shared/concat.rb b/spec/ruby/library/stringscanner/shared/concat.rb index 1dbae11f7c..8138b0f8dc 100644 --- a/spec/ruby/library/stringscanner/shared/concat.rb +++ b/spec/ruby/library/stringscanner/shared/concat.rb @@ -3,28 +3,28 @@ describe :strscan_concat, shared: true do s = StringScanner.new(+"hello ") s.send(@method, 'world').should == s s.string.should == "hello world" - s.eos?.should be_false + s.eos?.should == false end it "raises a TypeError if the given argument can't be converted to a String" do - -> { StringScanner.new('hello').send(@method, :world) }.should raise_error(TypeError) - -> { StringScanner.new('hello').send(@method, mock('x')) }.should raise_error(TypeError) + -> { StringScanner.new('hello').send(@method, :world) }.should.raise(TypeError) + -> { StringScanner.new('hello').send(@method, mock('x')) }.should.raise(TypeError) end end describe :strscan_concat_fixnum, shared: true do it "raises a TypeError" do a = StringScanner.new("hello world") - -> { a.send(@method, 333) }.should raise_error(TypeError) + -> { a.send(@method, 333) }.should.raise(TypeError) b = StringScanner.new("") - -> { b.send(@method, (256 * 3 + 64)) }.should raise_error(TypeError) - -> { b.send(@method, -200) }.should raise_error(TypeError) + -> { b.send(@method, (256 * 3 + 64)) }.should.raise(TypeError) + -> { b.send(@method, -200) }.should.raise(TypeError) end it "doesn't call to_int on the argument" do x = mock('x') x.should_not_receive(:to_int) - -> { StringScanner.new("").send(@method, x) }.should raise_error(TypeError) + -> { StringScanner.new("").send(@method, x) }.should.raise(TypeError) end end diff --git a/spec/ruby/library/stringscanner/shared/eos.rb b/spec/ruby/library/stringscanner/shared/eos.rb deleted file mode 100644 index ea04c764a2..0000000000 --- a/spec/ruby/library/stringscanner/shared/eos.rb +++ /dev/null @@ -1,17 +0,0 @@ -describe :strscan_eos, shared: true do - before :each do - @s = StringScanner.new("This is a test") - end - - it "returns true if the scan pointer is at the end of the string" do - @s.terminate - @s.send(@method).should be_true - - s = StringScanner.new('') - s.send(@method).should be_true - end - - it "returns false if the scan pointer is not at the end of the string" do - @s.send(@method).should be_false - end -end diff --git a/spec/ruby/library/stringscanner/shared/extract_range.rb b/spec/ruby/library/stringscanner/shared/extract_range.rb index e7404fd0cb..c64cc41fa7 100644 --- a/spec/ruby/library/stringscanner/shared/extract_range.rb +++ b/spec/ruby/library/stringscanner/shared/extract_range.rb @@ -5,7 +5,7 @@ describe :extract_range, shared: true do s = StringScanner.new(sub) ch = s.send(@method) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) + ch.should_not.is_a?(cls) + ch.should.instance_of?(String) end end diff --git a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb index 070a132812..8a6349bec1 100644 --- a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb +++ b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb @@ -7,7 +7,7 @@ describe :extract_range_matched, shared: true do s.scan(/\w{1}/) ch = s.send(@method) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) + ch.should_not.is_a?(cls) + ch.should.instance_of?(String) end end diff --git a/spec/ruby/library/stringscanner/shared/get_byte.rb b/spec/ruby/library/stringscanner/shared/get_byte.rb deleted file mode 100644 index 763ab6f4a4..0000000000 --- a/spec/ruby/library/stringscanner/shared/get_byte.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding: binary -*- -describe :strscan_get_byte, shared: true do - it "scans one byte and returns it" do - s = StringScanner.new('abc5.') - s.send(@method).should == 'a' - s.send(@method).should == 'b' - s.send(@method).should == 'c' - s.send(@method).should == '5' - s.send(@method).should == '.' - end - - it "is not multi-byte character sensitive" do - s = StringScanner.new("\244\242") - s.send(@method).should == "\244" - s.send(@method).should == "\242" - end - - it "returns nil at the end of the string" do - # empty string case - s = StringScanner.new('') - s.send(@method).should == nil - s.send(@method).should == nil - - # non-empty string case - s = StringScanner.new('a') - s.send(@method) # skip one - s.send(@method).should == nil - end -end diff --git a/spec/ruby/library/stringscanner/shared/peek.rb b/spec/ruby/library/stringscanner/shared/peek.rb deleted file mode 100644 index 4c757866c1..0000000000 --- a/spec/ruby/library/stringscanner/shared/peek.rb +++ /dev/null @@ -1,39 +0,0 @@ -describe :strscan_peek, shared: true do - before :each do - @s = StringScanner.new('This is a test') - end - - it "returns at most the specified number of bytes from the current position" do - @s.send(@method, 4).should == "This" - @s.pos.should == 0 - @s.pos = 5 - @s.send(@method, 2).should == "is" - @s.send(@method, 1000).should == "is a test" - - s = StringScanner.new("été") - s.send(@method, 2).should == "é" - end - - it "returns an empty string when the passed argument is zero" do - @s.send(@method, 0).should == "" - end - - it "raises a ArgumentError when the passed argument is negative" do - -> { @s.send(@method, -2) }.should raise_error(ArgumentError) - end - - it "raises a RangeError when the passed argument is a Bignum" do - -> { @s.send(@method, bignum_value) }.should raise_error(RangeError) - end - - it "returns an instance of String when passed a String subclass" do - cls = Class.new(String) - sub = cls.new("abc") - - s = StringScanner.new(sub) - - ch = s.send(@method, 1) - ch.should_not be_kind_of(cls) - ch.should be_an_instance_of(String) - end -end diff --git a/spec/ruby/library/stringscanner/shared/pos.rb b/spec/ruby/library/stringscanner/shared/pos.rb index 6d540881f2..91f80fdf08 100644 --- a/spec/ruby/library/stringscanner/shared/pos.rb +++ b/spec/ruby/library/stringscanner/shared/pos.rb @@ -22,6 +22,13 @@ describe :strscan_pos, shared: true do @s.terminate @s.send(@method).should == @s.string.length end + + it "is not multi-byte character sensitive" do + s = StringScanner.new("abcädeföghi") + + s.scan_until(/ö/) + s.pos.should == 10 + end end describe :strscan_pos_set, shared: true do @@ -43,10 +50,10 @@ describe :strscan_pos_set, shared: true do it "raises a RangeError if position too far backward" do -> { @s.send(@method, -20) - }.should raise_error(RangeError) + }.should.raise(RangeError) end it "raises a RangeError when the passed argument is out of range" do - -> { @s.send(@method, 20) }.should raise_error(RangeError) + -> { @s.send(@method, 20) }.should.raise(RangeError) end end diff --git a/spec/ruby/library/stringscanner/shared/rest_size.rb b/spec/ruby/library/stringscanner/shared/rest_size.rb deleted file mode 100644 index 4c4f49e45c..0000000000 --- a/spec/ruby/library/stringscanner/shared/rest_size.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :strscan_rest_size, shared: true do - before :each do - @s = StringScanner.new('This is a test') - end - - it "returns the length of the rest of the string" do - @s.send(@method).should == 14 - @s.scan(/This/) - @s.send(@method).should == 10 - @s.terminate - @s.send(@method).should == 0 - end - - it "is equivalent to rest.size" do - @s.scan(/This/) - @s.send(@method).should == @s.rest.size - end -end diff --git a/spec/ruby/library/stringscanner/shared/terminate.rb b/spec/ruby/library/stringscanner/shared/terminate.rb deleted file mode 100644 index bf41d097e2..0000000000 --- a/spec/ruby/library/stringscanner/shared/terminate.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :strscan_terminate, shared: true do - it "set the scan pointer to the end of the string and clear matching data." do - s = StringScanner.new('This is a test') - s.send(@method) - s.bol?.should be_false - s.eos?.should be_true - end -end |
