summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-02 12:45:42 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-02 12:45:42 +0000
commit7eb625425c3acb33ea712bc36bbe17302cfbca94 (patch)
tree18bc67e124c8ee9ee6331289c7cf6d133f29f07b /test
parent8a5dd664e7dd66f63fdf7bf7b6ff2fdef715db3a (diff)
* re.c: fix SEGV by Regexp.allocate.names, Match.allocate.names, etc.
* test/ruby/test_regexp.rb: add tests for above. * io.c: fix SEGV by IO.allocate.print, etc. * test/ruby/test_io.rb: add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io.rb4
-rw-r--r--test/ruby/test_regexp.rb41
2 files changed, 45 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 25ceb70be9..6e6a27f015 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1219,4 +1219,8 @@ class TestIO < Test::Unit::TestCase
assert_equal("bar\n", File.read(t.path, 4, 4))
end
+
+ def test_uninitialized
+ assert_raise(IOError) { IO.allocate.print "" }
+ end
end
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 52f931532b..970ad4d4d7 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -676,4 +676,45 @@ class TestRegexp < Test::Unit::TestCase
assert_equal(3, ("foo" + "bar" * 1000).rindex(/#{"bar"*1000}/))
assert_equal(4, ("foo\nbar\nbaz\n").rindex(/bar/i))
end
+
+ def test_uninitialized
+ assert_raise(TypeError) { Regexp.allocate.hash }
+ assert_raise(TypeError) { Regexp.allocate.eql? Regexp.allocate }
+ assert_raise(TypeError) { Regexp.allocate == Regexp.allocate }
+ assert_raise(TypeError) { Regexp.allocate =~ "" }
+ assert_equal(false, Regexp.allocate === Regexp.allocate)
+ assert_nil(~Regexp.allocate)
+ assert_raise(TypeError) { Regexp.allocate.match("") }
+ assert_raise(TypeError) { Regexp.allocate.to_s }
+ assert_raise(TypeError) { Regexp.allocate.inspect }
+ assert_raise(TypeError) { Regexp.allocate.source }
+ assert_raise(TypeError) { Regexp.allocate.casefold? }
+ assert_raise(TypeError) { Regexp.allocate.options }
+ assert_equal(Encoding.find("ASCII-8BIT"), Regexp.allocate.encoding)
+ assert_equal(false, Regexp.allocate.fixed_encoding?)
+ assert_raise(TypeError) { Regexp.allocate.names }
+ assert_raise(TypeError) { Regexp.allocate.named_captures }
+
+ assert_raise(TypeError) { MatchData.allocate.regexp }
+ assert_raise(TypeError) { MatchData.allocate.names }
+ assert_raise(TypeError) { MatchData.allocate.size }
+ assert_raise(TypeError) { MatchData.allocate.length }
+ assert_raise(TypeError) { MatchData.allocate.offset(0) }
+ assert_raise(TypeError) { MatchData.allocate.begin(0) }
+ assert_raise(TypeError) { MatchData.allocate.end(0) }
+ assert_raise(TypeError) { MatchData.allocate.to_a }
+ assert_raise(TypeError) { MatchData.allocate[:foo] }
+ assert_raise(TypeError) { MatchData.allocate.captures }
+ assert_raise(TypeError) { MatchData.allocate.values_at }
+ assert_raise(TypeError) { MatchData.allocate.pre_match }
+ assert_raise(TypeError) { MatchData.allocate.post_match }
+ assert_raise(TypeError) { MatchData.allocate.to_s }
+ assert_match(/^#<MatchData:.*>$/, MatchData.allocate.inspect)
+ assert_raise(TypeError) { MatchData.allocate.string }
+ $~ = MatchData.allocate
+ assert_raise(TypeError) { $& }
+ assert_raise(TypeError) { $` }
+ assert_raise(TypeError) { $' }
+ assert_raise(TypeError) { $+ }
+ end
end