From b64a3e41202c86e5eaa410fe182b3dfdb2b0dc4c Mon Sep 17 00:00:00 2001 From: nagachika Date: Tue, 11 Feb 2014 14:55:00 +0000 Subject: merge revision(s) r42479,r42490,r42509,r43083,r43084,r43085: [Backport #8756] [Backport #9248] * parse.y (rb_enc_symname_type): allow ID_ATTRSET for ID_INSTANCE, ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756] * parse.y (rb_id_attrset): fix inconsistency with literals, allow ID_ATTRSET and return it itself, but ID_JUNK cannot make ID_ATTRSET. and raise a NameError instead of rb_bug() for invalid argument. * parse.y (rb_id_attrset, intern_str): allow junk attrset ID for Struct. * parse.y (rb_id_attrset): check if the argument is valid type as an attribute. * parse.y (rb_id_attrset): allow other than ID_ATTRSET. * parse.y (intern_str): ditto. try stem ID for ID_INSTANCE, ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_struct.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 1c108777ee..db74438734 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -142,7 +142,19 @@ class TestStruct < Test::Unit::TestCase klass = Struct.new(:@a) o = klass.new(1) + assert_equal(1, o.__send__(:@a)) assert_equal("#", o.inspect) + o.__send__(:"@a=", 2) + assert_equal(2, o.__send__(:@a)) + assert_equal("#", o.inspect) + o.__send__("@a=", 3) + assert_equal(3, o.__send__(:@a)) + assert_equal("#", o.inspect) + + methods = klass.instance_methods(false) + assert_equal([:@a, :"@a="].inspect, methods.inspect, '[Bug #8756]') + assert_include(methods, :@a) + assert_include(methods, :"@a=") end def test_init_copy @@ -281,4 +293,10 @@ class TestStruct < Test::Unit::TestCase o = klass.new(1, 2, 3, 4, 5, 6) assert_equal({a:1, b:2, c:3, d:4, e:5, f:6}, o.to_h) end + + def test_struct_question_mark + bug9248 = '[ruby-core:59095]' + klass = Struct.new(:a?) + assert_include(klass.new.methods.inspect, ':a?', bug9248) + end end -- cgit v1.2.3