-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_calls.dry
36 lines (30 loc) · 1.2 KB
/
test_calls.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
def test_function_partial_application() {
let sum = lambda(x, y) { return x + y; };
let onePlus = sum(1, _);
assert_equals("Supply first function arg only", onePlus(3), 4);
assert_equals("Supply second function arg only", sum(_, 3)(7), 10);
}
def test_method_partial_application() {
class HasMinus {
def minus(x, y) {
return x - y;
}
}
let tenMinus = HasMinus().minus(10, _);
assert_equals("Supply first method arg only", tenMinus(6), 4);
assert_equals("Supply second method arg only", HasMinus().minus(_, 4)(15), 11);
}
def test_non_callable() {
assert_error_type("true is not callable", NotCallableError, lambda() { true(); });
assert_error_type("none is not callable", NotCallableError, lambda() { none(); });
assert_error_type("A number is not callable", NotCallableError, lambda() { 123(); });
assert_error_type("A class instance is not callable", NotCallableError, lambda() {
class Foo {}
let foo = Foo();
foo();
});
assert_error_type("A string is not callable", NotCallableError, lambda() { "str"(); });
}
test_function_partial_application();
test_method_partial_application();
test_non_callable();