|
1 | 1 | require_relative "test_helper" |
2 | 2 |
|
3 | | -class ClassTest < StdlibTest |
4 | | - target Class |
| 3 | +class ClassSingletonTest < Test::Unit::TestCase |
| 4 | + include TestHelper |
5 | 5 |
|
6 | | - def test_singleton_new |
7 | | - Class.new() |
8 | | - Class.new(Integer) |
9 | | - Class.new { } |
| 6 | + testing "singleton(::Class)" |
| 7 | + |
| 8 | + def test_allocate |
| 9 | + assert_send_type "() -> untyped", |
| 10 | + Class, :new |
10 | 11 | end |
| 12 | +end |
| 13 | + |
| 14 | +class ClassInstanceTest < Test::Unit::TestCase |
| 15 | + include TestHelper |
| 16 | + |
| 17 | + testing "::Class" |
| 18 | + |
| 19 | + Subclass = Class.new |
11 | 20 |
|
12 | 21 | def test_allocate |
13 | | - Class.new.allocate |
| 22 | + assert_send_type "() -> untyped", |
| 23 | + Subclass, :new |
14 | 24 | end |
15 | 25 |
|
16 | | - def test_instance_new |
17 | | - Class.new.new |
| 26 | + def test_new |
| 27 | + assert_send_type '() -> untyped', |
| 28 | + Subclass, :new |
| 29 | + |
| 30 | + big_init = Class.new do |
| 31 | + def initialize(*a, **k, &b) = nil |
| 32 | + end |
| 33 | + |
| 34 | + assert_send_type '(*untyped, **untyped) { (?) -> untyped } -> untyped', |
| 35 | + big_init, :new, 1, 2, a: 3, 'b' => 4 do |x, y, &z| 3 end |
18 | 36 | end |
19 | 37 |
|
20 | | - def test_super_class |
21 | | - Class.new.superclass |
22 | | - BasicObject.superclass |
| 38 | + def test_initialize |
| 39 | + assert_send_type "() -> void", |
| 40 | + Class.allocate, :initialize |
| 41 | + |
| 42 | + assert_send_type "() { (Class) [self: Class] -> void } -> void", |
| 43 | + Class.allocate, :initialize do end |
| 44 | + |
| 45 | + assert_send_type "(Class) -> void", |
| 46 | + Class.allocate, :initialize, String |
| 47 | + |
| 48 | + assert_send_type "(Class) { (Class) [self: Class] -> void } -> void", |
| 49 | + Class.allocate, :initialize, String do end |
| 50 | + end |
| 51 | + |
| 52 | + def test_superclass |
| 53 | + assert_send_type "() -> Class", |
| 54 | + String, :superclass |
| 55 | + assert_send_type "() -> nil", |
| 56 | + BasicObject, :superclass |
23 | 57 | end |
24 | 58 |
|
25 | 59 | def test_subclasses |
26 | | - Class.new.subclasses |
| 60 | + assert_send_type "() -> Array[Class]", |
| 61 | + Module, :subclasses |
27 | 62 | end |
28 | 63 |
|
29 | 64 | def test_attached_object |
30 | | - Class.new.singleton_class.attached_object |
| 65 | + assert_send_type "() -> untyped", |
| 66 | + Subclass.new.singleton_class, :attached_object |
| 67 | + end |
| 68 | + |
| 69 | + def test_inherited |
| 70 | + assert_send_type "(Class) -> void", |
| 71 | + Subclass, :inherited, String |
31 | 72 | end |
32 | 73 | end |
0 commit comments