[macruby-changes] [1442] MacRuby/branches/experimental/spec/frozen/language/regexp_spec.rb
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 22 15:07:37 PDT 2009
Revision: 1442
http://trac.macosforge.org/projects/ruby/changeset/1442
Author: eloy.de.enige at gmail.com
Date: 2009-04-22 15:07:35 -0700 (Wed, 22 Apr 2009)
Log Message:
-----------
Add specs for backref pseudo-globals
Modified Paths:
--------------
MacRuby/branches/experimental/spec/frozen/language/regexp_spec.rb
Modified: MacRuby/branches/experimental/spec/frozen/language/regexp_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/language/regexp_spec.rb 2009-04-22 22:07:24 UTC (rev 1441)
+++ MacRuby/branches/experimental/spec/frozen/language/regexp_spec.rb 2009-04-22 22:07:35 UTC (rev 1442)
@@ -701,7 +701,45 @@
/foo/ensuensuens.should == /foo/s
end
end
-
+
+ #############################################################################
+ # Back-refs
+ #############################################################################
+
+ it 'saves match data in the $~ pseudo-global variable' do
+ "hello" =~ /l+/
+ $~.to_a.should == ["ll"]
+ end
+
+ it 'saves captures in numbered $[1-9] variables' do
+ "1234567890" =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/
+ $~.to_a.should == ["1234567890", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
+ $1.should == "1"
+ $2.should == "2"
+ $3.should == "3"
+ $4.should == "4"
+ $5.should == "5"
+ $6.should == "6"
+ $7.should == "7"
+ $8.should == "8"
+ $9.should == "9"
+ end
+
+ it 'will not clobber capture variables across threads' do
+ cap1, cap2, cap3 = nil
+ "foo" =~ /(o+)/
+ cap1 = [$~.to_a, $1]
+ Thread.new do
+ cap2 = [$~.to_a, $1]
+ "bar" =~ /(a)/
+ cap3 = [$~.to_a, $1]
+ end.join
+ cap4 = [$~.to_a, $1]
+ cap1.should == [["oo", "oo"], "oo"]
+ cap2.should == [[], nil]
+ cap3.should == [["a", "a"], "a"]
+ cap4.should == [["oo", "oo"], "oo"]
+ end
end
language_version __FILE__, "regexp"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090422/c7dcb868/attachment.html>
More information about the macruby-changes
mailing list