Skip to content

Commit b0cea0b

Browse files
committed
regex tests and fix
1 parent dbf063f commit b0cea0b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/decoding.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Base.getindex(s::StringView, r::UnitRange{<:Integer}) = s[Int(first(r)):Int(last
7777
end
7878
j = nextind(s, j) - 1
7979
n = j - i + 1
80-
ss = _string_n(n)
80+
ss = Base._string_n(n)
8181
GC.@preserve s ss unsafe_copyto!(pointer(ss), pointer(s, i), n)
8282
return ss
8383
end

test/runtests.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ end
5353
end
5454

5555
@testset "regular expressions" begin
56-
@test [m.match for m in collect(eachmatch(r"[aeiou]+", s))] == ["oo", "a"] ==
57-
[m.match for m in collect(eachmatch(r"[aeiou]+", ss))]
56+
for str in (s,ss)
57+
@test [m.match for m in collect(eachmatch(r"[aeiou]+", str))] == ["oo", "a"]
58+
@test occursin(r"o+", str) && !occursin(r"z+", str)
59+
@test startswith(str, r"o+") == (str[1:2] == "oo")
60+
@test startswith(str, r"f+") == (str[1:2] == "fo")
61+
@test endswith(str, r"[aeiou]") == (str[end] == 'a')
62+
@test endswith(str, r"[q-z]") == (str[end] == 'r')
63+
@test findnext(r"o+", str, 4) === nothing
64+
end
65+
@test findnext(r"[aeiou]+", s, 1) == 2:3
66+
@test findnext(r"[aeiou]+", ss, 1) == 1:2
5867
end
5968

6069
@testset "miscellaneous" begin

0 commit comments

Comments
 (0)