Skip to content

Commit 3f3c205

Browse files
committed
rename hasinteger(x) -> has(x, Integer)
This will make it easy to test for something else than `Integer`.
1 parent d20f521 commit 3f3c205

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/ReTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function resolve!(mod::Module, ts::TestsetExpr, pat::Pattern;
282282
desc = ts.desc
283283
ts.loopvalues = nothing # unnecessary ?
284284
ts.loopiters = nothing
285-
if 0 != ts.id != id && !warned[] && hasinteger(pat)
285+
if 0 != ts.id != id && !warned[] && has(pat, Integer)
286286
# this can happen when nested testsets are added and Revise is active
287287
@warn "testset IDs have changed since last run"
288288
warned[] = true
@@ -737,7 +737,7 @@ function retest(@nospecialize(args::ArgType...);
737737
end
738738

739739
id = verbose > 0 && something(id, dry || any(modules) do (mod, pat)
740-
hasinteger(pat)
740+
has(pat, Integer)
741741
end)
742742

743743
descwidth = maximum(x->x[2], tests_descs_hasbrokens)

src/patterns.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ matches(::Union{Pass,Fail}, ::Missing, ts) =
137137
isempty(ts.marks) ? false : missing
138138

139139

140+
## has
141+
142+
# has(pat, T) checks whether pat recursively "contains" something of type T
143+
has(pat, T::Type) = pat isa T
144+
has(pat::Union{And,Or}, T::Type) = pat isa T || any(p -> has(p, T), pat.xs)
145+
has(pat::Union{Not,Reachable}, T::Type) = pat isa T || has(pat.x, T)
146+
147+
140148
## make_pattern
141149

142150
make_pattern(x::PatternX) = x
@@ -167,19 +175,6 @@ make_pattern(pat::AbstractArray{<:Integer}) = Or(pat)
167175
make_pattern(@nospecialize(pat::Tuple)) = And(PatternX[make_pattern(p) for p in pat])
168176

169177

170-
## hasinteger
171-
172-
hasinteger(::Regex) = false
173-
hasinteger(::Integer) = true
174-
hasinteger(pat::Union{And,Or}) = any(hasinteger, pat.xs)
175-
hasinteger(pat::Not) = hasinteger(pat.x)
176-
hasinteger(::Interpolated) = false
177-
hasinteger(pat::Reachable) = hasinteger(pat.x)
178-
hasinteger(::Depth) = false
179-
hasinteger(::Pass) = false
180-
hasinteger(::Fail) = false
181-
182-
183178
## exported pattern functions & singletons
184179

185180

test/test_patterns.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
@test ReTest.matches(a, "a", MockTestset()) isa Union{Missing, Bool}
6060
@test ReTest.matches(a, missing, MockTestset()) isa Union{Missing, Bool}
6161
@test ReTest.alwaysmatches(a, 1) isa Bool
62-
@test ReTest.hasinteger(a) isa Bool
62+
@test ReTest.has(a, Integer) isa Bool
6363
end
6464
end
6565

0 commit comments

Comments
 (0)