11using REPL # Hack to get around: https://github.com/JuliaLang/julia/issues/52986
22import CodeTracking: code_string
3+ import DocStringExtensions: MethodSignatures
34const DSE = DocStringExtensions
45
56include (" templates.jl" )
@@ -144,30 +145,34 @@ end
144145 end
145146
146147 @testset " method signatures" begin
148+ UntypedSignatures (x) = MethodSignatures (x, false )
149+
147150 doc. data = Dict (
148151 :binding => Docs. Binding (M, :f ),
149152 :typesig => Tuple{Any},
150153 :module => M,
151154 )
152- DSE. format (SIGNATURES, buf, doc)
155+
156+ DSE. format (UntypedSignatures (get_expr (M. f)), buf, doc)
153157 str = String (take! (buf))
154158 @test occursin (" \n ```julia\n " , str)
155159 @test occursin (" \n f(x)\n " , str)
156160 @test occursin (" \n ```\n " , str)
157161
162+ g_expr = get_expr (M. g, Int, Int, Int)
158163 doc. data = Dict (
159164 :binding => Docs. Binding (M, :g ),
160165 :typesig => Union{Tuple{}, Tuple{Any}},
161166 :module => M,
162167 )
163- DSE. format (SIGNATURES , buf, doc)
168+ DSE. format (UntypedSignatures (g_expr) , buf, doc)
164169 str = String (take! (buf))
165170 @test occursin (" \n ```julia\n " , str)
166171 # On 1.10+, automatically generated methods have keywords in the metadata,
167172 # hence the display difference between Julia versions.
168173 if VERSION >= v " 1.10"
169- @test occursin (" \n g(; ...)\n " , str)
170- @test occursin (" \n g(x; ...)\n " , str)
174+ @test occursin (" \n g(; kwargs ...)\n " , str)
175+ @test occursin (" \n g(x=1; kwargs ...)\n " , str)
171176 else
172177 @test occursin (" \n g()\n " , str)
173178 @test occursin (" \n g()\n " , str)
@@ -179,29 +184,29 @@ end
179184 :typesig => Union{Tuple{}, Tuple{Any}, Tuple{Any, Any}, Tuple{Any, Any, Any}},
180185 :module => M,
181186 )
182- DSE. format (SIGNATURES , buf, doc)
187+ DSE. format (UntypedSignatures (g_expr) , buf, doc)
183188 str = String (take! (buf))
184189 @test occursin (" \n ```julia\n " , str)
185190 # On 1.10+, automatically generated methods have keywords in the metadata,
186191 # hence the display difference between Julia versions.
187192 if VERSION >= v " 1.10"
188- @test occursin (" \n g(; ...)\n " , str)
189- @test occursin (" \n g(x; ...)\n " , str)
190- @test occursin (" \n g(x, y; ...)\n " , str)
193+ @test occursin (" \n g(; kwargs ...)\n " , str)
194+ @test occursin (" \n g(x=1; kwargs ...)\n " , str)
195+ @test occursin (" \n g(x=1 , y=2; kwargs ...)\n " , str)
191196 else
192197 @test occursin (" \n g()\n " , str)
193- @test occursin (" \n g(x)\n " , str)
194- @test occursin (" \n g(x, y)\n " , str)
198+ @test occursin (" \n g(x=1 )\n " , str)
199+ @test occursin (" \n g(x=1 , y=2 )\n " , str)
195200 end
196- @test occursin (" \n g(x, y, z; kwargs...)\n " , str)
201+ @test occursin (" \n g(x=1 , y=2 , z=3 ; kwargs...)\n " , str)
197202 @test occursin (" \n ```\n " , str)
198203
199204 doc. data = Dict (
200205 :binding => Docs. Binding (M, :g_1 ),
201206 :typesig => Tuple{Any},
202207 :module => M,
203208 )
204- DSE. format (SIGNATURES , buf, doc)
209+ DSE. format (UntypedSignatures ( get_expr (M . g_1)) , buf, doc)
205210 str = String (take! (buf))
206211 @test occursin (" \n ```julia\n " , str)
207212 @test occursin (" \n g_1(x)\n " , str)
212217 :typesig => Union{Tuple{Any, Int, Any}},
213218 :module => M,
214219 )
215- DSE. format (SIGNATURES , buf, doc)
220+ DSE. format (UntypedSignatures ( get_expr (M . h_4)) , buf, doc)
216221 str = String (take! (buf))
217222 @test occursin (" \n ```julia\n " , str)
218223 @test occursin (" \n h_4(x, _, z)\n " , str)
226231 :module => M,
227232 )
228233
229- DSE. format (TypedMethodSignatures (get_expr (M. h_1)), buf, doc)
234+ TypedSignatures (x) = MethodSignatures (x, true )
235+
236+ DSE. format (TypedSignatures (get_expr (M. h_1)), buf, doc)
230237 str = String (take! (buf))
231238 @test occursin (" \n ```julia\n " , str)
232239 f = str -> replace (str, " " => " " )
243250 :typesig => Tuple{String},
244251 :module => M,
245252 )
246- DSE. format (TypedMethodSignatures (get_expr (M. g_2)), buf, doc)
253+ DSE. format (TypedSignatures (get_expr (M. g_2)), buf, doc)
247254 str = String (take! (buf))
248255 @test occursin (" \n ```julia\n " , str)
249256 @test occursin (" \n g_2(x::String)" , str)
255262 :typesig => Tuple{Int, Int, Int},
256263 :module => M,
257264 )
258- DSE. format (TypedMethodSignatures (h_expr), buf, doc)
265+ DSE. format (TypedSignatures (h_expr), buf, doc)
259266 str = String (take! (buf))
260267 @test occursin (" \n ```julia\n " , str)
261268 if typeof (1 ) === Int64
270277 :typesig => Tuple{Int},
271278 :module => M,
272279 )
273- DSE. format (TypedMethodSignatures (h_expr), buf, doc)
280+ DSE. format (TypedSignatures (h_expr), buf, doc)
274281 str = String (take! (buf))
275282 @test occursin (" \n ```julia\n " , str)
276283 if typeof (1 ) === Int64
297304 :typesig => Tuple{T} where T,
298305 :module => M,
299306 )
300- DSE. format (TypedMethodSignatures (get_expr (M. k_0)), buf, doc)
307+ DSE. format (TypedSignatures (get_expr (M. k_0)), buf, doc)
301308 str = String (take! (buf))
302309 @test occursin (" \n ```julia\n " , str)
303310 @test occursin (" \n k_0(x) -> Any\n " , str)
309316 :module => M,
310317 )
311318 k_1_expr = get_expr (M. k_1, String, Int, Int)
312- DSE. format (TypedMethodSignatures (k_1_expr), buf, doc)
319+ DSE. format (TypedSignatures (k_1_expr), buf, doc)
313320 str = String (take! (buf))
314321 @test occursin (" \n ```julia\n " , str)
315322 @test occursin (" \n k_1(x::String) -> String\n " , str)
322329 :typesig => (Union{Tuple{String, U, T}, Tuple{T}, Tuple{U}} where T <: Number ) where U <: Complex ,
323330 :module => M,
324331 )
325- DSE. format (TypedMethodSignatures (get_expr (M. k_2)), buf, doc)
332+ DSE. format (TypedSignatures (get_expr (M. k_2)), buf, doc)
326333 str = String (take! (buf))
327334 @test occursin (" \n ```julia\n " , str)
328335 @test occursin (" k_2(x::String, y::Complex, z::Number) -> String" , str)
333340 :typesig => (Union{Tuple{Any, T, U}, Tuple{U}, Tuple{T}} where U <: Any ) where T <: Any ,
334341 :module => M,
335342 )
336- DSE. format (TypedMethodSignatures (get_expr (M. k_3)), buf, doc)
343+ DSE. format (TypedSignatures (get_expr (M. k_3)), buf, doc)
337344 str = String (take! (buf))
338345 @test occursin (" \n ```julia\n " , str)
339346 @test occursin (" \n k_3(x, y, z) -> Any\n " , str)
344351 :typesig => Union{Tuple{String}, Tuple{String, Int}},
345352 :module => M,
346353 )
347- DSE. format (TypedMethodSignatures (get_expr (M. k_4, String, Int)), buf, doc)
354+ DSE. format (TypedSignatures (get_expr (M. k_4, String, Int)), buf, doc)
348355 str = String (take! (buf))
349356 @test occursin (" \n ```julia\n " , str)
350357 if VERSION > v " 1.3.0"
367374 :typesig => Union{Tuple{Type{T}, String}, Tuple{Type{T}, String, Union{Nothing, Function}}, Tuple{T}} where T <: Number ,
368375 :module => M,
369376 )
370- DSE. format (TypedMethodSignatures (get_expr (M. k_5, Type{Int}, String, Nothing)), buf, doc)
377+ DSE. format (TypedSignatures (get_expr (M. k_5, Type{Int}, String, Nothing)), buf, doc)
371378 str = String (take! (buf))
372379 @test occursin (" \n ```julia\n " , str)
373380 if VERSION > v " 1.3.0"
386393 :typesig => Union{Tuple{Vector{T}}, Tuple{T}} where T <: Number ,
387394 :module => M,
388395 )
389- DSE. format (TypedMethodSignatures (get_expr (M. k_6)), buf, doc)
396+ DSE. format (TypedSignatures (get_expr (M. k_6)), buf, doc)
390397 f = str -> replace (str, " " => " " )
391398 str = String (take! (buf))
392399 str = f (str)
404411 :typesig => Union{Tuple{Union{Nothing, T}}, Tuple{T}, Tuple{Union{Nothing, T}, T}} where T<: Integer ,
405412 :module => M,
406413 )
407- DSE. format (TypedMethodSignatures (get_expr (M. k_7, Nothing, Int)), buf, doc)
414+ DSE. format (TypedSignatures (get_expr (M. k_7, Nothing, Int)), buf, doc)
408415 str = String (take! (buf))
409416 @test occursin (" \n ```julia\n " , str)
410417 if VERSION >= v " 1.6" && VERSION < v " 1.7"
421428 :typesig => Union{Tuple{Any}},
422429 :module => M,
423430 )
424- DSE. format (TypedMethodSignatures (get_expr (M. k_8)), buf, doc)
431+ DSE. format (TypedSignatures (get_expr (M. k_8)), buf, doc)
425432 str = String (take! (buf))
426433 @test occursin (" \n ```julia\n " , str)
427434 @test occursin (" \n k_8(x) -> Any\n " , str)
432439 :typesig => Union{Tuple{T where T}},
433440 :module => M,
434441 )
435- DSE. format (TypedMethodSignatures (get_expr (M. k_9)), buf, doc)
442+ DSE. format (TypedSignatures (get_expr (M. k_9)), buf, doc)
436443 str = String (take! (buf))
437444 @test occursin (" \n ```julia\n " , str)
438445 @test occursin (" \n k_9(x) -> Any\n " , str)
445452 :typesig => Union{Tuple{Int, Vararg{Any}}},
446453 :module => M,
447454 )
448- DSE. format (TypedMethodSignatures (get_expr (M. k_11)), buf, doc)
455+ DSE. format (TypedSignatures (get_expr (M. k_11)), buf, doc)
449456 str = String (take! (buf))
450457 @test occursin (" \n ```julia\n " , str)
451458 @test occursin (" \n k_11(x::Int64, xs...) -> Int64\n " , str)
456463 :typesig => Union{Tuple{Int, Vararg{Real}}},
457464 :module => M,
458465 )
459- DSE. format (TypedMethodSignatures (get_expr (M. k_12)), buf, doc)
466+ DSE. format (TypedSignatures (get_expr (M. k_12)), buf, doc)
460467 str = String (take! (buf))
461468 @test occursin (" \n ```julia\n " , str)
462469 @test occursin (" \n k_12(x::Int64, xs::Real...) -> Int64\n " , str)
0 commit comments