File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,8 @@ function getindex(m::RegexMatch, name::Symbol)
168
168
end
169
169
getindex (m:: RegexMatch , name:: AbstractString ) = m[Symbol (name)]
170
170
171
+ iterate (m:: RegexMatch ) = iterate (m. captures)
172
+
171
173
function occursin (r:: Regex , s:: AbstractString ; offset:: Integer = 0 )
172
174
compile (r)
173
175
return PCRE. exec_r (r. regex, String (s), offset, r. match_options)
Original file line number Diff line number Diff line change 136
136
@test r" this|that" ^ 2 == r" (?:this|that){2}"
137
137
end
138
138
139
+ @testset " iterate" begin
140
+ m = match (r" (.) test (.+)" , " a test 123" )
141
+ @test first (m) == " a"
142
+ @test collect (m) == [" a" , " 123" ]
143
+ @test for (i, capture) in m
144
+ i == 1 && @test capture == " a"
145
+ i == 2 && @test capture == " 123"
146
+ end
147
+ end
148
+
149
+ @testset " Destructuring dispatch" begin
150
+ handle (:: Nothing ) = " not found"
151
+ handle ((capture,):: RegexMatch ) = " found $capture "
152
+
153
+ @test handle (match (r" a (\d )" , " xyz" )) == " not found"
154
+ @test handle (match (r" a (\d )" , " a 1" )) == " found 1"
155
+ end
156
+
139
157
# Test that PCRE throws the correct kind of error
140
158
# TODO : Uncomment this once the corresponding change has propagated to CI
141
159
# @test_throws ErrorException Base.PCRE.info(C_NULL, Base.PCRE.INFO_NAMECOUNT, UInt32)
You can’t perform that action at this time.
0 commit comments