diff --git a/src/bindings.jl b/src/bindings.jl index 80de075..220fd5b 100644 --- a/src/bindings.jl +++ b/src/bindings.jl @@ -106,6 +106,11 @@ function ingest_default!(b::Bindings, expr::Expr) ingest_default!(b, arg) end + # Core.Int and Base.Random.rand + elseif expr.head == :. + reference = expr + !(reference in b.internal) && push!(b.external, reference) + else error("expression is not valid as a parameter default: $expr") end diff --git a/test/REQUIRE b/test/REQUIRE index 4aebb28..5e92eb6 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1 @@ -Compat 0.33 +Compat 0.37 diff --git a/test/bindings/ingest_assertion.jl b/test/bindings/ingest_assertion.jl index 3ab5329..eafdefb 100644 --- a/test/bindings/ingest_assertion.jl +++ b/test/bindings/ingest_assertion.jl @@ -1,5 +1,4 @@ import Mocking: Bindings, ingest_assertion! -import Base.Dates: Hour @testset "assertion" begin b = Bindings([:T], []) diff --git a/test/bindings/ingest_default.jl b/test/bindings/ingest_default.jl index 4b03f36..0cc818b 100644 --- a/test/bindings/ingest_default.jl +++ b/test/bindings/ingest_default.jl @@ -15,4 +15,9 @@ import Mocking: Bindings, ingest_default! ingest_default!(b, :(f(rand(Bool)))) @test b.internal == Set() @test b.external == Set([:f, :rand, :Bool]) + + b = Bindings() + ingest_default!(b, :(f(rand(Base.Bool)))) + @test b.internal == Set() + @test b.external == Set([:f, :rand, :(Base.Bool)]) end diff --git a/test/expr.jl b/test/expr.jl index a8f4593..a92e27f 100644 --- a/test/expr.jl +++ b/test/expr.jl @@ -1,6 +1,8 @@ -import Base.Dates: Hour +import Compat: Dates +import Dates: Hour const INT_EXPR = Int === Int32 ? :(Core.Int32) : :(Core.Int64) +const HOUR_EXPR = VERSION < v"0.7.0-DEV.2575" ? :(Base.Dates.Hour) : :(Dates.Hour) @testset "joinbinding" begin @test Mocking.joinbinding(:Foo) == :(Foo) @@ -18,9 +20,8 @@ end @test Mocking.binding_expr(Int) == INT_EXPR # typealias. TODO: Change to Core.Int? Shouldn't actually matter @test Mocking.binding_expr(Int64) == :(Core.Int64) # concrete type @test Mocking.binding_expr(Integer) == :(Core.Integer) # abstract type - @test Mocking.binding_expr(Hour) == :(Base.Dates.Hour) # unexported type - @test Mocking.binding_expr(Dates.Hour) == :(Base.Dates.Hour) # submodule - @test Mocking.binding_expr(Base.Dates.Hour) == :(Base.Dates.Hour) # full type binding + @test Mocking.binding_expr(Hour) == HOUR_EXPR # unexported type + @test Mocking.binding_expr(Dates.Hour) == HOUR_EXPR # submodule @test Mocking.binding_expr(rand) == :(Base.Random.rand) # function @test Mocking.binding_expr(AbstractArray{Int64}) == :(Core.AbstractArray) # Core.AbstractArray{Int64}? # @test Mocking.binding_expr(AbstractArray{T}) == :(Core.AbstractArray{T}) diff --git a/test/import.jl b/test/import.jl index b3416cf..7c4fbbb 100644 --- a/test/import.jl +++ b/test/import.jl @@ -1,10 +1,11 @@ +import Compat: Dates import Compat: read # Patches should allow using imported bindings in the body of the patch @testset "imported binding in body" begin @test_throws UndefVarError Minute - @test isdefined(Base.Dates, :Minute) - import Base.Dates: Minute, Hour + @test isdefined(Dates, :Minute) + import Dates: Minute, Hour myminute(x::Integer) = Minute(x) diff --git a/test/optional.jl b/test/optional.jl index 018f34d..e2ed810 100644 --- a/test/optional.jl +++ b/test/optional.jl @@ -1,10 +1,11 @@ -import Base.Dates: Hour +import Compat: Dates +import Dates: Hour # Creating a patch with an optional parameter @testset "patch with optional parameter" begin - hourvalue(h::Hour=Hour(0)) = Base.Dates.value(h) + hourvalue(h::Hour=Hour(0)) = Dates.value(h) - patch = @patch hourvalue(h::Hour=Hour(21)) = 2 * Base.Dates.value(h) + patch = @patch hourvalue(h::Hour=Hour(21)) = 2 * Dates.value(h) apply(patch) do @test (@mock hourvalue()) == 42 @test (@mock hourvalue(Hour(4))) == 8 @@ -13,9 +14,9 @@ end # Creating a patch with an keyword parameter @testset "patch with keyword parameter" begin - hourvalue(; hour::Hour=Hour(0)) = Base.Dates.value(hour) + hourvalue(; hour::Hour=Hour(0)) = Dates.value(hour) - patch = @patch hourvalue(; hour::Hour=Hour(21)) = 2 * Base.Dates.value(hour) + patch = @patch hourvalue(; hour::Hour=Hour(21)) = 2 * Dates.value(hour) apply(patch) do @test (@mock hourvalue()) == 42 # @test (@mock hourvalue(hour=Hour(4))) == 8 # TODO diff --git a/test/patch.jl b/test/patch.jl index ffaf7bc..fa3bc25 100644 --- a/test/patch.jl +++ b/test/patch.jl @@ -1,5 +1,5 @@ -import Base: Dates -import Base.Dates: Hour +import Compat: Dates +import Dates: Hour @testset "patch" begin @testset "basic" begin @@ -30,13 +30,13 @@ import Base.Dates: Hour @testset "assertion qualification" begin patches = [ - @patch f(h::Base.Dates.Hour=Base.Dates.Hour(rand())) = nothing - @patch f(h::Dates.Hour=Dates.Hour(rand())) = nothing - @patch f(h::Hour=Hour(rand())) = nothing + @patch f(h::Base.Core.Int64=rand(Base.Core.Int64)) = nothing + @patch f(h::Core.Int64=rand(Core.Int64)) = nothing + @patch f(h::Int64=rand(Int64)) = nothing ] for p in patches - @test p.signature == :(f(h::Base.Dates.Hour=Base.Dates.Hour(Base.Random.rand()))) - @test p.modules == Set([:(Base.Dates), :(Base.Random)]) + @test p.signature == :(f(h::Core.Int64=Base.Random.rand(Core.Int64))) + @test p.modules == Set([:Core, :(Base.Random)]) end end end diff --git a/test/runtests.jl b/test/runtests.jl index 639cde0..3b0106e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,7 @@ using Mocking Mocking.enable(force=true) VERSION < v"0.7-" && import Compat: Test +import Compat: Dates using Test import Mocking: apply