-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_constructors.dry
42 lines (39 loc) · 1.12 KB
/
test_constructors.dry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class TestConstructors {
def test_arguments() {
class Foo {
def init(a, b) {
self.a = a;
self.b = b;
}
}
let foo = Foo(1, 2);
assert_equals("Constructor arguments", (1, 2), (foo.a, foo.b));
}
def test_early_return() {
class Foo {
def init() {
self.value = "init";
return;
self.value = "new value";
}
}
let foo = Foo();
assert_equals("Constructor early return", "init", foo.value);
}
def test_call_init_explicitly() {
class Foo {
def init() {
self.field = "init";
}
}
let foo = Foo();
foo.field = "field";
let foo2 = foo.init();
assert_equals("Explicitly create an instance via init", "init", foo.field);
assert_equals("Explicitly calling init does not create a new instance", (), foo2);
}
}
let constructors = TestConstructors();
constructors.test_arguments();
constructors.test_early_return();
constructors.test_call_init_explicitly();