summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringscanner/element_reference_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringscanner/element_reference_spec.rb')
-rw-r--r--spec/ruby/library/stringscanner/element_reference_spec.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/spec/ruby/library/stringscanner/element_reference_spec.rb b/spec/ruby/library/stringscanner/element_reference_spec.rb
index 60fe15d807..91b6d86dc7 100644
--- a/spec/ruby/library/stringscanner/element_reference_spec.rb
+++ b/spec/ruby/library/stringscanner/element_reference_spec.rb
@@ -8,6 +8,7 @@ describe "StringScanner#[]" do
it "returns nil if there is no current match" do
@s[0].should be_nil
+ @s[:wday].should be_nil
end
it "returns the n-th subgroup in the most recent match" do
@@ -42,12 +43,18 @@ describe "StringScanner#[]" do
-> { @s[0..2]}.should raise_error(TypeError)
end
- it "raises a IndexError when there's no named capture" do
+ it "raises a IndexError when there's no any named capture group in the regexp" do
@s.scan(/(\w+) (\w+) (\d+) /)
-> { @s["wday"]}.should raise_error(IndexError)
-> { @s[:wday]}.should raise_error(IndexError)
end
+ it "raises a IndexError when given a not existing capture group name" do
+ @s.scan(/(?<a>\w+) (?<b>\w+) (?<c>\d+) /)
+ -> { @s["wday"]}.should raise_error(IndexError)
+ -> { @s[:wday]}.should raise_error(IndexError)
+ end
+
it "returns named capture" do
@s.scan(/(?<wday>\w+) (?<month>\w+) (?<day>\d+) /)
@s["wday"].should == "Fri"