Skip to content

Commit 8f9aad4

Browse files
authored
Add some tests to increase code coverage (#15)
1 parent aa70647 commit 8f9aad4

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

test/runtests.jl

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ end
8484

8585
@testset "type" begin
8686
global Foo
87-
87+
8888
@kwdispatch Foo(_::String)
8989

9090
@kwmethod Foo(_::String;) = 10
@@ -124,7 +124,7 @@ struct Bar{T}
124124
end
125125
@testset "call overloading with ref" begin
126126
global Bar
127-
127+
128128
@kwdispatch (::Bar{Float64})
129129

130130
@kwmethod (t::Bar{Float64})(;) = t.w+13
@@ -173,7 +173,7 @@ end
173173
end
174174

175175

176-
@testset "different module" begin
176+
@testset "different module" begin
177177
@kwdispatch Base.RoundingMode
178178

179179
@kwmethod Base.RoundingMode(;) = 10
@@ -216,7 +216,7 @@ end
216216

217217
@testset "kwdispatch subtype extra arg" begin
218218
global Baz
219-
219+
220220
@kwdispatch (::Type{B})() where {B<:Baz} begin
221221
() -> B(0)
222222
(w) -> B(w)
@@ -233,7 +233,7 @@ end
233233
@test Baz(z=4) == Baz{Float64}(2.0)
234234
@test Baz{Int}(z=4) == Baz{Int}(2)
235235
@test Baz{Float64}(z=4) == Baz{Float64}(2.0)
236-
end
236+
end
237237

238238

239239
@testset "kw rename" begin
@@ -263,3 +263,31 @@ end
263263

264264
@test_throws KeywordMethodError f(1,y=[1.0,2.0])
265265
end
266+
267+
@testset "Base.showerror(::KeywordMethodError)" begin
268+
errs = [
269+
KeywordMethodError(sin, ("foo",), (; bar="baz")),
270+
KeywordMethodError(String, ("foo",), (; bar="baz")),
271+
KeywordMethodError("sin", ("foo",), (; bar="baz")),
272+
]
273+
expected_outputs = [
274+
"KeywordMethodError: no keyword method matching sin(::String; bar::String)",
275+
"KeywordMethodError: no keyword method matching String(::String; bar::String)",
276+
"KeywordMethodError: no keyword method matching (::String)(::String; bar::String)",
277+
]
278+
for i in 1:length(errs)
279+
err = errs[i]
280+
expected_output = expected_outputs[i]
281+
io = IOBuffer()
282+
Base.showerror(io, err)
283+
@test String(take!(io)) == expected_output
284+
end
285+
end
286+
287+
@testset "generate_kwmethods: \"Invalid keyword definition\" error" begin
288+
expr = :(
289+
for i= 1:10
290+
end
291+
)
292+
@test_throws ErrorException KeywordDispatch.generate_kwmethods(expr, nothing, nothing, nothing)
293+
end

0 commit comments

Comments
 (0)