Skip to content

Commit 6297d57

Browse files
authored
Use Aqua and JET in tests (#130)
* Use Aqua and JET in tests * Only run JET on 1.7.0+ * Add some type-annotations for JET
1 parent 223ec68 commit 6297d57

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1010
julia = "1"
1111

1212
[extras]
13+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
14+
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
1315
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1416

1517
[targets]
16-
test = ["Test"]
18+
test = ["Aqua", "Test", "JET"]

src/Parsers.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ function xparse(::Type{T}, source, pos, len, options, ::Type{S}=T) where {T, S}
242242
end
243243
end
244244

245+
xparse(::Type{Char}, buf::AbstractString, pos, len, options, ::Type{S}=Char) where {S} =
246+
xparse(Char, codeunits(buf), pos, len, options, S)
245247
function xparse(::Type{Char}, source, pos, len, options, ::Type{S}=Char) where {S}
246248
res = xparse(String, source, pos, len, options)
247249
code = res.code
@@ -253,8 +255,10 @@ function xparse(::Type{Char}, source, pos, len, options, ::Type{S}=Char) where {
253255
end
254256
end
255257

258+
xparse(::Type{Symbol}, buf::AbstractString, pos, len, options, ::Type{S}=Symbol) where {S} =
259+
xparse(Symbol, codeunits(buf), pos, len, options, S)
256260
function xparse(::Type{Symbol}, source, pos, len, options, ::Type{S}=Symbol) where {S}
257-
res = xparse(String, source, pos, len, options)
261+
res = xparse(String, source, pos, len, options, PosLen)
258262
code = res.code
259263
poslen = res.val
260264
if !Parsers.invalid(code) && !Parsers.sentinel(code)

src/floats.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ end
206206
end
207207
if has_groupmark
208208
b, nb = dpeekbyte(source, pos) .- UInt8('0')
209-
if options.groupmark - UInt8('0') == b && nb <= 0x09
209+
if (options.groupmark)::UInt8 - UInt8('0') == b && nb <= 0x09
210210
incr!(source)
211211
pos += 1
212212
b = nb

src/ints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ overflowval(::Type{T}) where {T <: Integer} = div(typemax(T) - T(9), T(10))
3535
end
3636
if has_groupmark
3737
b, nb = dpeekbyte(source, pos) .- UInt8('0')
38-
if options.groupmark - UInt8('0') == b && nb <= 0x09
38+
if (options.groupmark)::UInt8 - UInt8('0') == b && nb <= 0x09
3939
incr!(source)
4040
pos += 1
4141
b = nb
@@ -78,7 +78,7 @@ overflowval(::Type{T}) where {T <: Integer} = div(typemax(T) - T(9), T(10))
7878
end
7979
if has_groupmark
8080
b, nb = dpeekbyte(source, pos) .- UInt8('0')
81-
if options.groupmark - UInt8('0') == b && nb <= 0x09
81+
if (options.groupmark)::UInt8 - UInt8('0') == b && nb <= 0x09
8282
incr!(source)
8383
pos += 1
8484
b = nb

src/strings.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# this is mostly copy-pasta from Parsers.jl main xparse function
2+
xparse(::Type{T}, buf::AbstractString, pos, len, options, ::Type{S}=PosLen) where {T <: AbstractString, S} =
3+
xparse(String, codeunits(buf), pos, len, options, S)
24
function xparse(::Type{T}, source::Union{AbstractVector{UInt8}, IO}, pos, len, options, ::Type{S}=PosLen) where {T <: AbstractString, S}
35
startpos = vstartpos = vpos = lastnonwhitespacepos = pos
46
sentstart = sentinelpos = 0

test/runtests.jl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Parsers, Test, Dates
22

33
import Parsers: INVALID, OK, SENTINEL, QUOTED, DELIMITED, NEWLINE, EOF, INVALID_QUOTED_FIELD, INVALID_DELIMITER, OVERFLOW, ESCAPED_STRING
4-
4+
import Aqua
55
struct CustomType
66
x::String
77
end
@@ -601,4 +601,35 @@ include("floats.jl")
601601
include("dates.jl")
602602
include("ryu.jl")
603603

604+
605+
@testset "Aqua.jl" begin
606+
Aqua.test_all(Parsers)
607+
end
608+
609+
@static if Base.VERSION >= v"1.7"
610+
import JET
611+
@testset "JET.jl" begin
612+
@testset "Optimization" begin
613+
for S in (String, Vector{UInt8}, IOBuffer)
614+
for T in (String, Symbol, Char, Int64, Int32, UInt64, UInt32, Float64, Float32, Bool)
615+
JET.test_opt(Parsers.xparse, Tuple{Type{T}, S, Int, Int, Parsers.Options, Type{T === String ? PosLen : T}})
616+
end
617+
end
618+
619+
JET.test_opt(Parsers.xparse, Tuple{Type{Date}, String, Int, Int, Parsers.Options, Type{Date}})
620+
JET.test_opt(Parsers.xparse, Tuple{Type{Time}, String, Int, Int, Parsers.Options, Type{Time}})
621+
for S in (Vector{UInt8}, IOBuffer)
622+
for T in (Dates.Date, Dates.Time)
623+
JET.test_opt(Parsers.xparse, Tuple{Type{T}, S, Int, Int, Parsers.Options, Type{T}}, broken=true)
624+
end
625+
end
626+
end
627+
@testset "Typos" begin
628+
res = JET.report_package(Parsers, mode=:typo, toplevel_logger=nothing);
629+
@test isempty(res.res.toplevel_error_reports)
630+
!isempty(res.res.toplevel_error_reports) && display(res)
631+
end
632+
end
633+
end
634+
604635
end # @testset "Parsers"

0 commit comments

Comments
 (0)