@@ -4,7 +4,7 @@ defmodule Kernel.GuardTest do
4
4
use ExUnit.Case , async: true
5
5
6
6
describe "Kernel.defguard(p) usage" do
7
- defmodule Guards.In.Macros do
7
+ defmodule GuardsInMacros do
8
8
defguard is_foo ( atom ) when atom == :foo
9
9
10
10
defmacro is_compile_time_foo ( atom ) when is_foo ( atom ) do
@@ -13,13 +13,13 @@ defmodule Kernel.GuardTest do
13
13
end
14
14
15
15
test "guards can be used in other macros in the same module" do
16
- require Guards.In.Macros
17
- assert Guards.In.Macros . is_foo ( :foo )
18
- refute Guards.In.Macros . is_foo ( :baz )
19
- assert Guards.In.Macros . is_compile_time_foo ( :foo )
16
+ require GuardsInMacros
17
+ assert GuardsInMacros . is_foo ( :foo )
18
+ refute GuardsInMacros . is_foo ( :baz )
19
+ assert GuardsInMacros . is_compile_time_foo ( :foo )
20
20
end
21
21
22
- defmodule Guards.In.Funs do
22
+ defmodule GuardsInFuns do
23
23
defguard is_foo ( atom ) when atom == :foo
24
24
defguard is_equal ( foo , bar ) when foo == bar
25
25
@@ -29,19 +29,19 @@ defmodule Kernel.GuardTest do
29
29
end
30
30
31
31
test "guards can be used in other funs in the same module" do
32
- require Guards.In.Funs
33
- assert Guards.In.Funs . is_foo ( :foo )
34
- refute Guards.In.Funs . is_foo ( :bar )
32
+ require GuardsInFuns
33
+ assert GuardsInFuns . is_foo ( :foo )
34
+ refute GuardsInFuns . is_foo ( :bar )
35
35
end
36
36
37
37
test "guards do not change code evaluation semantics" do
38
- require Guards.In.Funs
38
+ require GuardsInFuns
39
39
x = 1
40
- assert Guards.In.Funs . is_equal ( x = 2 , x ) == false
40
+ assert GuardsInFuns . is_equal ( x = 2 , x ) == false
41
41
assert x == 2
42
42
end
43
43
44
- defmodule Macros.In.Guards do
44
+ defmodule MacrosInGuards do
45
45
defmacro is_foo ( atom ) do
46
46
quote do
47
47
unquote ( atom ) == :foo
@@ -52,35 +52,35 @@ defmodule Kernel.GuardTest do
52
52
end
53
53
54
54
test "macros can be used in other guards in the same module" do
55
- require Macros.In.Guards
56
- assert Macros.In.Guards . is_foobar ( :foo )
57
- assert Macros.In.Guards . is_foobar ( :bar )
58
- refute Macros.In.Guards . is_foobar ( :baz )
55
+ require MacrosInGuards
56
+ assert MacrosInGuards . is_foobar ( :foo )
57
+ assert MacrosInGuards . is_foobar ( :bar )
58
+ refute MacrosInGuards . is_foobar ( :baz )
59
59
end
60
60
61
- defmodule Guards.In.Guards do
61
+ defmodule GuardsInGuards do
62
62
defguard is_foo ( atom ) when atom == :foo
63
63
defguard is_foobar ( atom ) when is_foo ( atom ) or atom == :bar
64
64
end
65
65
66
66
test "guards can be used in other guards in the same module" do
67
- require Guards.In.Guards
68
- assert Guards.In.Guards . is_foobar ( :foo )
69
- assert Guards.In.Guards . is_foobar ( :bar )
70
- refute Guards.In.Guards . is_foobar ( :baz )
67
+ require GuardsInGuards
68
+ assert GuardsInGuards . is_foobar ( :foo )
69
+ assert GuardsInGuards . is_foobar ( :bar )
70
+ refute GuardsInGuards . is_foobar ( :baz )
71
71
end
72
72
73
- defmodule Default.Args do
73
+ defmodule DefaultArgs do
74
74
defguard is_divisible ( value , remainder \\ 2 )
75
75
when is_integer ( value ) and rem ( value , remainder ) == 0
76
76
end
77
77
78
78
test "permits default values in args" do
79
- require Default.Args
80
- assert Default.Args . is_divisible ( 2 )
81
- refute Default.Args . is_divisible ( 1 )
82
- assert Default.Args . is_divisible ( 3 , 3 )
83
- refute Default.Args . is_divisible ( 3 , 4 )
79
+ require DefaultArgs
80
+ assert DefaultArgs . is_divisible ( 2 )
81
+ refute DefaultArgs . is_divisible ( 1 )
82
+ assert DefaultArgs . is_divisible ( 3 , 3 )
83
+ refute DefaultArgs . is_divisible ( 3 , 4 )
84
84
end
85
85
86
86
test "doesn't allow matching in args" do
@@ -109,7 +109,7 @@ defmodule Kernel.GuardTest do
109
109
end
110
110
end
111
111
112
- defmodule Integer.Private.Guards do
112
+ defmodule IntegerPrivateGuards do
113
113
defguardp is_even ( value ) when is_integer ( value ) and rem ( value , 2 ) == 0
114
114
115
115
def is_even_and_large? ( value ) when is_even ( value ) and value > 100 , do: true
@@ -121,28 +121,28 @@ defmodule Kernel.GuardTest do
121
121
end
122
122
123
123
test "defguardp defines private guards that work inside and outside guard clauses" do
124
- assert Integer.Private.Guards . is_even_and_large? ( 102 )
125
- refute Integer.Private.Guards . is_even_and_large? ( 98 )
126
- refute Integer.Private.Guards . is_even_and_large? ( 99 )
127
- refute Integer.Private.Guards . is_even_and_large? ( 103 )
124
+ assert IntegerPrivateGuards . is_even_and_large? ( 102 )
125
+ refute IntegerPrivateGuards . is_even_and_large? ( 98 )
126
+ refute IntegerPrivateGuards . is_even_and_large? ( 99 )
127
+ refute IntegerPrivateGuards . is_even_and_large? ( 103 )
128
128
129
- assert Integer.Private.Guards . is_even_and_small? ( 98 )
130
- refute Integer.Private.Guards . is_even_and_small? ( 99 )
131
- refute Integer.Private.Guards . is_even_and_small? ( 102 )
132
- refute Integer.Private.Guards . is_even_and_small? ( 103 )
129
+ assert IntegerPrivateGuards . is_even_and_small? ( 98 )
130
+ refute IntegerPrivateGuards . is_even_and_small? ( 99 )
131
+ refute IntegerPrivateGuards . is_even_and_small? ( 102 )
132
+ refute IntegerPrivateGuards . is_even_and_small? ( 103 )
133
133
134
134
assert_raise CompileError , ~r" cannot invoke local is_even/1 inside guard" , fn ->
135
- defmodule Integer.Private.Guard.Utils do
136
- import Integer.Private.Guards
135
+ defmodule IntegerPrivateGuardUtils do
136
+ import IntegerPrivateGuards
137
137
138
138
def is_even_and_large? ( value ) when is_even ( value ) and value > 100 , do: true
139
139
def is_even_and_large? ( _ ) , do: false
140
140
end
141
141
end
142
142
143
143
assert_raise CompileError , ~r" undefined function is_even/1" , fn ->
144
- defmodule Integer.Private.Function.Utils do
145
- import Integer.Private.Guards
144
+ defmodule IntegerPrivateFunctionUtils do
145
+ import IntegerPrivateGuards
146
146
147
147
def is_even_and_small? ( value ) do
148
148
if is_even ( value ) and value <= 100 , do: true , else: false
0 commit comments