@@ -37,12 +37,36 @@ defmodule ExUnit.Filters do
37
37
iex> ExUnit.Filters.normalize([:foo, :bar, :bar], [:foo, :baz])
38
38
{[:foo, :bar], [:baz]}
39
39
40
+ iex> ExUnit.Filters.normalize([foo: "true"], [:foo])
41
+ {[foo: "true"], [:foo]}
42
+
43
+ iex> ExUnit.Filters.normalize([:foo], [foo: "true"])
44
+ {[:foo], []}
45
+
46
+ iex> ExUnit.Filters.normalize([foo: "true"], [foo: true])
47
+ {[foo: "true"], []}
48
+
49
+ iex> ExUnit.Filters.normalize([foo: true], [foo: "true"])
50
+ {[foo: true], []}
51
+
40
52
"""
41
53
@ spec normalize ( t | nil , t | nil ) :: { t , t }
42
54
def normalize ( include , exclude ) do
43
- include = include |> List . wrap ( ) |> Enum . uniq ( )
44
- exclude = exclude |> List . wrap ( ) |> Enum . uniq ( ) |> Kernel . -- ( include )
45
- { include , exclude }
55
+ { include_atoms , include_tags } =
56
+ include |> List . wrap ( ) |> Enum . uniq ( ) |> Enum . split_with ( & is_atom / 1 )
57
+
58
+ { exclude_atoms , exclude_tags } =
59
+ exclude |> List . wrap ( ) |> Enum . uniq ( ) |> Enum . split_with ( & is_atom / 1 )
60
+
61
+ exclude_tags = Map . new ( exclude_tags )
62
+
63
+ exclude_included =
64
+ for include_tag <- include_tags , key = has_tag ( include_tag , exclude_tags ) , do: key
65
+
66
+ exclude_tags =
67
+ exclude_tags |> Map . drop ( include_atoms ) |> Map . drop ( exclude_included ) |> Map . to_list ( )
68
+
69
+ { include_atoms ++ include_tags , ( exclude_atoms -- include_atoms ) ++ exclude_tags }
46
70
end
47
71
48
72
@ doc """
@@ -121,22 +145,26 @@ defmodule ExUnit.Filters do
121
145
end
122
146
end
123
147
124
- defp has_tag ( { key , % Regex { } = value } , tags , _collection ) when is_atom ( key ) do
148
+ defp has_tag ( pair , tags , _collection ) do
149
+ has_tag ( pair , tags )
150
+ end
151
+
152
+ defp has_tag ( { key , % Regex { } = value } , tags ) when is_atom ( key ) do
125
153
case Map . fetch ( tags , key ) do
126
154
{ :ok , tag } -> to_string ( tag ) =~ value and key
127
155
_ -> false
128
156
end
129
157
end
130
158
131
- defp has_tag ( { key , value } , tags , _collection ) when is_atom ( key ) do
159
+ defp has_tag ( { key , value } , tags ) when is_atom ( key ) do
132
160
case Map . fetch ( tags , key ) do
133
161
{ :ok , ^ value } -> key
134
162
{ :ok , tag } -> compare ( to_string ( tag ) , to_string ( value ) ) and key
135
163
_ -> false
136
164
end
137
165
end
138
166
139
- defp has_tag ( key , tags , _collection ) when is_atom ( key ) , do: Map . has_key? ( tags , key ) and key
167
+ defp has_tag ( key , tags ) when is_atom ( key ) , do: Map . has_key? ( tags , key ) and key
140
168
141
169
defp to_integer ( integer ) when is_integer ( integer ) , do: integer
142
170
defp to_integer ( integer ) when is_binary ( integer ) , do: String . to_integer ( integer )
0 commit comments