Skip to content

Commit 40e4a99

Browse files
committed
tests: test "interface" methods on patterns
I.e. `matches`, `alwaysmatches`, `hasinteger`.
1 parent fdf2e5a commit 40e4a99

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

test/test_patterns.jl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
module TestPatterns
22
using Test
33

4-
using ReTest: and, or, not, interpolated, reachable, depth
4+
using ReTest: and, or, not, interpolated, reachable, depth, pass, fail
5+
import ReTest
6+
7+
struct MockTestset
8+
id
9+
pastresults
10+
parent
11+
12+
MockTestset() = new(rand(1:typemax(Int)), Dict(), nothing)
13+
end
14+
15+
ReTest.tsdepth(::MockTestset) = 1
16+
17+
const basic_patterns = [and(), or(), not(0), interpolated, 0, r"", depth(2), pass, fail]
18+
VERSION >= v"1.3" && push!(basic_patterns, reachable(1))
519

620
@testset "patterns: ==" begin
7-
basics = [and(), or(), not(0), interpolated, 0, r"", depth(2)]
8-
VERSION >= v"1.3" && push!(basics, reachable(1))
9-
for a = basics, b = basics
21+
for a = basic_patterns, b = basic_patterns
1022
if a === b
1123
@test a == b
1224
if !(a isa Regex || a isa Integer)
@@ -42,6 +54,15 @@ using ReTest: and, or, not, interpolated, reachable, depth
4254
end
4355
end
4456

57+
@testset "patterns: interface" begin
58+
for a in basic_patterns
59+
@test ReTest.matches(a, "a", MockTestset()) isa Union{Missing, Bool}
60+
@test ReTest.matches(a, missing, MockTestset()) isa Union{Missing, Bool}
61+
@test ReTest.alwaysmatches(a, 1) isa Bool
62+
@test ReTest.hasinteger(a) isa Bool
63+
end
64+
end
65+
4566
@testset "patterns: not" begin
4667
pats = [or(1, 3), and(1, r"a"), not(1), interpolated, depth(3)]
4768
VERSION >= v"1.3" && push!(pats, reachable("c"))

0 commit comments

Comments
 (0)