mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Undefine MatchData.allocate [Feature #16294]
This commit is contained in:
parent
7460c884fb
commit
aa94245a09
2 changed files with 6 additions and 0 deletions
1
re.c
1
re.c
|
@ -4110,6 +4110,7 @@ Init_Regexp(void)
|
||||||
rb_cMatch = rb_define_class("MatchData", rb_cObject);
|
rb_cMatch = rb_define_class("MatchData", rb_cObject);
|
||||||
rb_define_alloc_func(rb_cMatch, match_alloc);
|
rb_define_alloc_func(rb_cMatch, match_alloc);
|
||||||
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
||||||
|
rb_undef_method(CLASS_OF(rb_cMatch), "allocate");
|
||||||
|
|
||||||
rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
|
rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
|
||||||
rb_define_method(rb_cMatch, "regexp", match_regexp, 0);
|
rb_define_method(rb_cMatch, "regexp", match_regexp, 0);
|
||||||
|
|
|
@ -1002,6 +1002,8 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
assert_raise(TypeError) { Regexp.allocate.names }
|
assert_raise(TypeError) { Regexp.allocate.names }
|
||||||
assert_raise(TypeError) { Regexp.allocate.named_captures }
|
assert_raise(TypeError) { Regexp.allocate.named_captures }
|
||||||
|
|
||||||
|
assert_not_respond_to(MatchData, :allocate)
|
||||||
|
=begin
|
||||||
assert_raise(TypeError) { MatchData.allocate.hash }
|
assert_raise(TypeError) { MatchData.allocate.hash }
|
||||||
assert_raise(TypeError) { MatchData.allocate.regexp }
|
assert_raise(TypeError) { MatchData.allocate.regexp }
|
||||||
assert_raise(TypeError) { MatchData.allocate.names }
|
assert_raise(TypeError) { MatchData.allocate.names }
|
||||||
|
@ -1024,6 +1026,7 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
assert_raise(TypeError) { $` }
|
assert_raise(TypeError) { $` }
|
||||||
assert_raise(TypeError) { $' }
|
assert_raise(TypeError) { $' }
|
||||||
assert_raise(TypeError) { $+ }
|
assert_raise(TypeError) { $+ }
|
||||||
|
=end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unicode
|
def test_unicode
|
||||||
|
@ -1093,7 +1096,9 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
assert_equal(a, b, '[ruby-core:24748]')
|
assert_equal(a, b, '[ruby-core:24748]')
|
||||||
h = {a => 42}
|
h = {a => 42}
|
||||||
assert_equal(42, h[b], '[ruby-core:24748]')
|
assert_equal(42, h[b], '[ruby-core:24748]')
|
||||||
|
=begin
|
||||||
assert_match(/#<TestRegexp::MatchData_\u{3042}:/, MatchData_A.allocate.inspect)
|
assert_match(/#<TestRegexp::MatchData_\u{3042}:/, MatchData_A.allocate.inspect)
|
||||||
|
=end
|
||||||
|
|
||||||
h = /^(?<@time>\d+): (?<body>.*)/.match("123456: hoge fuga")
|
h = /^(?<@time>\d+): (?<body>.*)/.match("123456: hoge fuga")
|
||||||
assert_equal("123456", h["@time"])
|
assert_equal("123456", h["@time"])
|
||||||
|
|
Loading…
Reference in a new issue