summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringscanner
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-11-29 15:50:28 +0100
committerBenoit Daloze <eregontp@gmail.com>2021-11-29 15:50:28 +0100
commit67a1e2258974df4b597d019739595c18fbb9a7c1 (patch)
tree992ad4fc0fc08a6af8f04373703a339f957eb143 /spec/ruby/library/stringscanner
parente6d93a27afa058319e6dad093bbef637e49fce47 (diff)
Update to ruby/spec@7f22a0b
Diffstat (limited to 'spec/ruby/library/stringscanner')
-rw-r--r--spec/ruby/library/stringscanner/check_until_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/exist_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/matched_size_spec.rb21
-rw-r--r--spec/ruby/library/stringscanner/scan_until_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/search_full_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/shared/matched_size.rb21
-rw-r--r--spec/ruby/library/stringscanner/size_spec.rb17
-rw-r--r--spec/ruby/library/stringscanner/skip_until_spec.rb6
8 files changed, 66 insertions, 23 deletions
diff --git a/spec/ruby/library/stringscanner/check_until_spec.rb b/spec/ruby/library/stringscanner/check_until_spec.rb
index e92ae5a2e9..ad222fd76b 100644
--- a/spec/ruby/library/stringscanner/check_until_spec.rb
+++ b/spec/ruby/library/stringscanner/check_until_spec.rb
@@ -12,4 +12,10 @@ describe "StringScanner#check_until" do
@s.matched.should == "a"
@s.check_until(/test/).should == "This is a test"
end
+
+ it "raises TypeError if given a String" do
+ -> {
+ @s.check_until('T')
+ }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)')
+ end
end
diff --git a/spec/ruby/library/stringscanner/exist_spec.rb b/spec/ruby/library/stringscanner/exist_spec.rb
index beafadc07b..ff860a0d3e 100644
--- a/spec/ruby/library/stringscanner/exist_spec.rb
+++ b/spec/ruby/library/stringscanner/exist_spec.rb
@@ -21,4 +21,10 @@ describe "StringScanner#exist?" do
@s.scan(/This is/)
@s.exist?(/i/).should == nil
end
+
+ it "raises TypeError if given a String" do
+ -> {
+ @s.exist?('T')
+ }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)')
+ end
end
diff --git a/spec/ruby/library/stringscanner/matched_size_spec.rb b/spec/ruby/library/stringscanner/matched_size_spec.rb
index a36bd3aafe..d9c338a07e 100644
--- a/spec/ruby/library/stringscanner/matched_size_spec.rb
+++ b/spec/ruby/library/stringscanner/matched_size_spec.rb
@@ -1,7 +1,24 @@
require_relative '../../spec_helper'
-require_relative 'shared/matched_size'
require 'strscan'
describe "StringScanner#matched_size" do
- it_behaves_like :strscan_matched_size, :matched_size
+ before :each do
+ @s = StringScanner.new("This is a test")
+ end
+
+ it "returns the size of the most recent match" do
+ @s.check(/This/)
+ @s.matched_size.should == 4
+ @s.matched_size.should == 4
+ @s.scan(//)
+ @s.matched_size.should == 0
+ end
+
+ it "returns nil if there was no recent match" do
+ @s.matched_size.should == nil
+ @s.check(/\d+/)
+ @s.matched_size.should == nil
+ @s.terminate
+ @s.matched_size.should == nil
+ end
end
diff --git a/spec/ruby/library/stringscanner/scan_until_spec.rb b/spec/ruby/library/stringscanner/scan_until_spec.rb
index 94239db50e..6b7782572d 100644
--- a/spec/ruby/library/stringscanner/scan_until_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_until_spec.rb
@@ -20,4 +20,10 @@ describe "StringScanner#scan_until" do
@s.scan(/T/)
@s.scan_until(/^h/).should == "h"
end
+
+ it "raises TypeError if given a String" do
+ -> {
+ @s.scan_until('T')
+ }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)')
+ end
end
diff --git a/spec/ruby/library/stringscanner/search_full_spec.rb b/spec/ruby/library/stringscanner/search_full_spec.rb
index da9067e012..7d2a714fa5 100644
--- a/spec/ruby/library/stringscanner/search_full_spec.rb
+++ b/spec/ruby/library/stringscanner/search_full_spec.rb
@@ -27,4 +27,10 @@ describe "StringScanner#search_full" do
@s.search_full(/This/, true, true).should == "This"
@s.pos.should == 4
end
+
+ it "raises TypeError if given a String" do
+ -> {
+ @s.search_full('T', true, true)
+ }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)')
+ end
end
diff --git a/spec/ruby/library/stringscanner/shared/matched_size.rb b/spec/ruby/library/stringscanner/shared/matched_size.rb
deleted file mode 100644
index 92174733f7..0000000000
--- a/spec/ruby/library/stringscanner/shared/matched_size.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-describe :strscan_matched_size, shared: true do
- before :each do
- @s = StringScanner.new("This is a test")
- end
-
- it "returns the size of the most recent match" do
- @s.check(/This/)
- @s.send(@method).should == 4
- @s.send(@method).should == 4
- @s.scan(//)
- @s.send(@method).should == 0
- end
-
- it "returns nil if there was no recent match" do
- @s.send(@method).should == nil
- @s.check(/\d+/)
- @s.send(@method).should == nil
- @s.terminate
- @s.send(@method).should == nil
- end
-end
diff --git a/spec/ruby/library/stringscanner/size_spec.rb b/spec/ruby/library/stringscanner/size_spec.rb
new file mode 100644
index 0000000000..3e475489e3
--- /dev/null
+++ b/spec/ruby/library/stringscanner/size_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+require 'strscan'
+
+describe "StringScanner#size" do
+ before :each do
+ @s = StringScanner.new("This is a test")
+ end
+
+ it "returns the number of captures groups of the last match" do
+ @s.scan(/(.)(.)(.)/)
+ @s.size.should == 4
+ end
+
+ it "returns nil if there is no last match" do
+ @s.size.should == nil
+ end
+end
diff --git a/spec/ruby/library/stringscanner/skip_until_spec.rb b/spec/ruby/library/stringscanner/skip_until_spec.rb
index 73eb91b8ad..7b56f13e4f 100644
--- a/spec/ruby/library/stringscanner/skip_until_spec.rb
+++ b/spec/ruby/library/stringscanner/skip_until_spec.rb
@@ -15,4 +15,10 @@ describe "StringScanner#skip_until" do
it "returns nil if no match was found" do
@s.skip_until(/d+/).should == nil
end
+
+ it "raises TypeError if given a String" do
+ -> {
+ @s.skip_until('T')
+ }.should raise_error(TypeError, 'wrong argument type String (expected Regexp)')
+ end
end