|
84 | 84 |
|
85 | 85 | @testset "type" begin
|
86 | 86 | global Foo
|
87 |
| - |
| 87 | + |
88 | 88 | @kwdispatch Foo(_::String)
|
89 | 89 |
|
90 | 90 | @kwmethod Foo(_::String;) = 10
|
@@ -124,7 +124,7 @@ struct Bar{T}
|
124 | 124 | end
|
125 | 125 | @testset "call overloading with ref" begin
|
126 | 126 | global Bar
|
127 |
| - |
| 127 | + |
128 | 128 | @kwdispatch (::Bar{Float64})
|
129 | 129 |
|
130 | 130 | @kwmethod (t::Bar{Float64})(;) = t.w+13
|
|
173 | 173 | end
|
174 | 174 |
|
175 | 175 |
|
176 |
| -@testset "different module" begin |
| 176 | +@testset "different module" begin |
177 | 177 | @kwdispatch Base.RoundingMode
|
178 | 178 |
|
179 | 179 | @kwmethod Base.RoundingMode(;) = 10
|
|
216 | 216 |
|
217 | 217 | @testset "kwdispatch subtype extra arg" begin
|
218 | 218 | global Baz
|
219 |
| - |
| 219 | + |
220 | 220 | @kwdispatch (::Type{B})() where {B<:Baz} begin
|
221 | 221 | () -> B(0)
|
222 | 222 | (w) -> B(w)
|
|
233 | 233 | @test Baz(z=4) == Baz{Float64}(2.0)
|
234 | 234 | @test Baz{Int}(z=4) == Baz{Int}(2)
|
235 | 235 | @test Baz{Float64}(z=4) == Baz{Float64}(2.0)
|
236 |
| -end |
| 236 | +end |
237 | 237 |
|
238 | 238 |
|
239 | 239 | @testset "kw rename" begin
|
|
263 | 263 |
|
264 | 264 | @test_throws KeywordMethodError f(1,y=[1.0,2.0])
|
265 | 265 | 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