summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_struct.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 5f073a3315..c313ab0dbe 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -118,10 +118,9 @@ module TestStruct
assert_equal "#{@Struct}::KeywordInitFalse", @Struct::KeywordInitFalse.inspect
assert_equal "#{@Struct}::KeywordInitTrue(keyword_init: true)", @Struct::KeywordInitTrue.inspect
# eval is needed to prevent the warning duplication filter
- k = eval("Class.new(@Struct::KeywordInitFalse) {def initialize(**) end}")
- assert_raise(ArgumentError) { k.new(a: 1, b: 2) }
- k = Class.new(@Struct::KeywordInitTrue) {def initialize(**) end}
- assert_warn('') {k.new(a: 1, b: 2)}
+ k = Class.new(@Struct::KeywordInitTrue) {def initialize(b, options); super(a: options, b: b); end}
+ o = assert_warn('') { k.new(42, {foo: 1, bar: 2}) }
+ assert_equal(1, o.a[:foo])
@Struct.instance_eval do
remove_const(:KeywordInitTrue)
@@ -150,6 +149,17 @@ module TestStruct
assert_equal 3, klass.new(1,2).total
end
+ def test_initialize_with_kw
+ klass = @Struct.new(:foo, :options) do
+ def initialize(foo, **options)
+ super(foo, options)
+ end
+ end
+ assert_equal({}, klass.new(42, **Hash.new).options)
+ x = assert_warn('') { klass.new(1, bar: 2) }
+ assert_equal 2, x.options[:bar]
+ end
+
def test_each
klass = @Struct.new(:a, :b)
o = klass.new(1, 2)