diff options
Diffstat (limited to 'test/ruby/test_struct.rb')
| -rw-r--r-- | test/ruby/test_struct.rb | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index ed750b91f7..176e2ac5de 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -41,14 +41,6 @@ module TestStruct end end - def test_larger_than_largest_pool - count = (GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE] / RbConfig::SIZEOF["void*"]) + 1 - list = Array(0..count) - klass = @Struct.new(*list.map { |i| :"a_#{i}"}) - struct = klass.new(*list) - assert_equal 0, struct.a_0 - end - def test_small_structs names = [:a, :b, :c, :d] 1.upto(4) {|n| @@ -108,9 +100,8 @@ module TestStruct assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members) end - def test_struct_new_with_hash - assert_raise_with_message(TypeError, /not a symbol/) {Struct.new(:a, {})} - assert_raise_with_message(TypeError, /not a symbol/) {Struct.new(:a, {name: "b"})} + def test_struct_new_with_empty_hash + assert_equal({:a=>1}, Struct.new(:a, {}).new({:a=>1}).a) end def test_struct_new_with_keyword_init @@ -371,8 +362,9 @@ module TestStruct end def test_keyword_args_warning - assert_warn('') { assert_equal(1, @Struct.new(:a).new(a: 1).a) } - assert_warn('') { assert_equal(1, @Struct.new(:a, keyword_init: nil).new(a: 1).a) } + warning = /warning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3\.2\./ + assert_warn(warning) { assert_equal({a: 1}, @Struct.new(:a).new(a: 1).a) } + assert_warn(warning) { assert_equal({a: 1}, @Struct.new(:a, keyword_init: nil).new(a: 1).a) } assert_warn('') { assert_equal({a: 1}, @Struct.new(:a).new({a: 1}).a) } assert_warn('') { assert_equal({a: 1}, @Struct.new(:a, :b).new(1, a: 1).b) } assert_warn('') { assert_equal(1, @Struct.new(:a, keyword_init: true).new(a: 1).a) } |
