-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathdecorate_all_test.exs
More file actions
77 lines (56 loc) · 1.97 KB
/
Copy pathdecorate_all_test.exs
File metadata and controls
77 lines (56 loc) · 1.97 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
defmodule DecoratorDecorateAllTest.Fixture.MyDecorator do
use Decorator.Define, some_decorator: 0
def some_decorator(body, _context) do
{:ok, body}
end
end
defmodule DecoratorDecorateAllTest.Fixture.MyModule do
use DecoratorDecorateAllTest.Fixture.MyDecorator
@decorate_all some_decorator()
def square(a) do
a * a
end
def answer, do: 24
def value123, do: 123
def value666, do: 666
def empty_body(a)
def empty_body(10), do: 11
def empty_body(n), do: n + 2
end
defmodule DecoratorDecorateAllTest.Fixture.MyModuleWithAttribute do
use DecoratorDecorateAllTest.Fixture.MyDecorator
@decorate_all some_decorator()
@custom_attr 15
@custom_attr_map %{some_val: 3, other_val: 10}
def fun1(x), do: x + 2
def fun2(x), do: x + @custom_attr
def fun3(x), do: x + @custom_attr_map[:some_val]
end
defmodule DecoratorDecorateAllTest.Fixture.MyModuleWithSeparatedClauses do
use DecoratorDecorateAllTest.Fixture.MyDecorator
@decorate_all some_decorator()
def fun1(0), do: :zero
def fun1(x), do: x
def fun2(x), do: x + 2
end
defmodule DecoratorDecorateAllTest do
use ExUnit.Case
alias DecoratorDecorateAllTest.Fixture.MyModule
alias DecoratorDecorateAllTest.Fixture.MyModuleWithAttribute
alias DecoratorDecorateAllTest.Fixture.MyModuleWithSeparatedClauses
test "decorate_all" do
assert {:ok, 4} == MyModule.square(2)
assert {:ok, 16} == MyModule.square(4)
assert {:ok, 24} == MyModule.answer()
assert {:ok, 123} == MyModule.value123()
assert {:ok, 666} == MyModule.value666()
assert {:ok, 11} == MyModule.empty_body(10)
assert {:ok, 8} == MyModule.empty_body(6)
assert {:ok, 10} == MyModuleWithAttribute.fun1(8)
assert {:ok, 20} == MyModuleWithAttribute.fun2(5)
assert {:ok, 8} == MyModuleWithAttribute.fun3(5)
assert {:ok, :zero} == MyModuleWithSeparatedClauses.fun1(0)
assert {:ok, 4} == MyModuleWithSeparatedClauses.fun2(2)
assert {:ok, 2} == MyModuleWithSeparatedClauses.fun1(2)
end
end