Skip to content

Commit 53c0fdb

Browse files
committed
✅ Test overriding inherited ::Data methods
TruffleRuby and JRuby each fail one or more of these.
1 parent 8c282c0 commit 53c0fdb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/net/imap/test_data_lite.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,43 @@ def other
340340
assert_equal("test", data.name)
341341
assert_equal("other", data.other)
342342
end
343+
344+
class Abstract < Data
345+
end
346+
347+
class Inherited < Abstract.define(:foo)
348+
end
349+
350+
def test_subclass_can_create
351+
assert_equal 1, Inherited[1] .foo
352+
assert_equal 2, Inherited[foo: 2].foo
353+
assert_equal 3, Inherited.new(3).foo
354+
assert_equal 4, Inherited.new(foo: 4).foo
355+
end
356+
357+
class AbstractWithClassMethod < Data
358+
def self.inherited_class_method; :ok end
359+
end
360+
361+
class InheritsClassMethod < AbstractWithClassMethod.define(:foo)
362+
end
363+
364+
def test_subclass_class_method
365+
assert_equal :ok, InheritsClassMethod.inherited_class_method
366+
end
367+
368+
class AbstractWithOverride < Data
369+
def deconstruct; [:ok, *super] end
370+
end
371+
372+
class InheritsOverride < AbstractWithOverride.define(:foo)
373+
end
374+
375+
def test_subclass_override_deconstruct
376+
data = InheritsOverride[:foo]
377+
assert_equal %i[ok foo], data.deconstruct
378+
end
379+
343380
end
344381
end
345382
end

0 commit comments

Comments
 (0)