3

目標は、メソッドと型のタプルを受け取り、true を返す関数を定義することです。これらの型は、そのメソッドの有効な入力です。機能ではなく、method

accepts(meth::Method, types::Tuple)::Bool

これがこのためのテストセットです

using Base.Test
@testset "accepts method checker" begin
    concrete = first(methods(length, (String,)))
    #length(s::String) in Base at strings/string.jl:162

    abstract_ = last(collect(methods(length,(AbstractArray,))))
    #length(t::AbstractArray) in Base at abstractarray.jl:131

    triangular = first(methods(length, (StepRange,)))
    # length(r::StepRange{T,S} where S) where T<:Union{Int64, UInt64} in Base at range.jl:381

    a = "hello"
    a_t = (typeof(a),) #(String,)
    @test accepts(concrete, a_t)
    @test !accepts(abstract_, a_t)
    @test !accepts(triangular, a_t)

    b = 1.5:10
    b_t = (typeof(b),) #(StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}})
    @test !accepts(concrete, b_t)
    @test accepts(abstract_, b_t)
    @test !accepts(triangular, b_t)

    c_t = (StepRange{Float64, Float64},) # Nothing real has this type as it can't be constructed
    @test !accepts(concrete, c_t)
    @test accepts(abstract_, c_t)
    @test !accepts(triangular, c_t)

    d = 1:2:10
    d_t = (typeof(d),) #(StepRange{Int64,Int64}
    @test !accepts(concrete, d_t)
    @test accepts(abstract_, d_t)
    @test accepts(triangular, d_t)
end

julia はパブリック リフレクション API をあまり持っていないので (私が以前に不満を持っていたように)、潜在的にすべてのパッチ バージョンを壊す可能性のあるコードには問題ありません。

この質問の目的は、 InterfaceTesting.jl のこの部分を 0.5 から 0.6に更新するために何をする必要があるかを理解できるようにすることです。

私の古いコードが機能しなくなった原因は、三角形のディスパッチを可能にするために導入された変更です。したがって、triangularテストは合格するのが難しいものです。

4

1 に答える 1