diff --git a/base/loading.jl b/base/loading.jl index 75b9d6e7e3b69..08a55b8c01405 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -90,10 +90,11 @@ struct SHA1 return new(bytes) end end -SHA1(s::Union{String,SubString{String}}) = SHA1(hex2bytes(s)) +SHA1(s::AbstractString) = SHA1(hex2bytes(s)) string(hash::SHA1) = bytes2hex(hash.bytes) +print(io::IO, hash::SHA1) = print(io, string(hash)) -show(io::IO, hash::SHA1) = print(io, "SHA1(", string(hash), ")") +show(io::IO, hash::SHA1) = print(io, "SHA1(\"", string(hash), "\")") isless(a::SHA1, b::SHA1) = lexless(a.bytes, b.bytes) hash(a::SHA1, h::UInt) = hash((SHA1, a.bytes), h) ==(a::SHA1, b::SHA1) = a.bytes == b.bytes diff --git a/base/uuid.jl b/base/uuid.jl index 72ce1aa6b293f..a1f3eb7c03f8d 100644 --- a/base/uuid.jl +++ b/base/uuid.jl @@ -59,4 +59,5 @@ let groupings = [36:-1:25; 23:-1:20; 18:-1:15; 13:-1:10; 8:-1:1] end end -show(io::IO, u::UUID) = write(io, string(u)) +print(io::IO, u::UUID) = print(io, string(u)) +show(io::IO, u::UUID) = print(io, "UUID(\"", u, "\")") diff --git a/test/loading.jl b/test/loading.jl index 3336fab4d272c..aa1bd829b7396 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -86,6 +86,20 @@ import UUIDs: UUID, uuid4, uuid_version import Random: shuffle, randstring using Test +let shastr = "ab"^20 + hash = SHA1(shastr) + @test hash == eval(Meta.parse(repr(hash))) # check show method + @test string(hash) == shastr + @test "check $hash" == "check $shastr" +end + +let uuidstr = "ab"^4 * "-" * "ab"^2 * "-" * "ab"^2 * "-" * "ab"^2 * "-" * "ab"^6 + uuid = UUID(uuidstr) + @test uuid == eval(Meta.parse(repr(uuid))) # check show method + @test string(uuid) == uuidstr + @test "check $uuid" == "check $uuidstr" +end + function subset(v::Vector{T}, m::Int) where T T[v[j] for j = 1:length(v) if ((m >>> (j - 1)) & 1) == 1] end