Skip to content

Commit

Permalink
fixes for julia 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 20, 2018
1 parent edcef68 commit 4386189
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/ColorTypes.jl
Expand Up @@ -7,13 +7,13 @@ using Base: @pure

import Compat
using Compat.TypeUtils
using Compat: @__MODULE__, isabstracttype, isconcretetype, uninitialized
using Compat: @__MODULE__, isabstracttype, isconcretetype, undef

const Fractional = Union{AbstractFloat, FixedPoint}
Base.@deprecate_binding U8 N0f8
Base.@deprecate_binding U16 N0f16

import Base: ==, isapprox, hash, convert, eltype, length, show, showcompact, oneunit, zero, reinterpret, rand, getindex
import Base: ==, isapprox, hash, convert, eltype, length, show, oneunit, zero, reinterpret, rand, getindex

## Types
export Fractional
Expand Down
10 changes: 4 additions & 6 deletions src/show.jl
@@ -1,7 +1,5 @@
show(io::IO, c::Colorant) = _show(io, c)
show(io::IO, c::ColorantNormed) = show_normed(io, c)
showcompact(io::IO, c::Colorant) = _showcompact(io, c)
showcompact(io::IO, c::ColorantNormed) = show_normed(io, c)
show(io::IO, c::Colorant) = get(io, :compact, false) ? _showcompact(io, c) : _show(io, c)
show(io::IO, c::ColorantNormed) = show_normed(io, c)

# Nonparametric types
show_normed(io::IO, c::Gray24) = print(io, "Gray24(", gray(c), ')')
Expand All @@ -10,7 +8,7 @@ show_normed(io::IO, c::ARGB32) = print(io, "ARGB32(", red(c), ',', green(c), ','

for N = 1:4
component = N >= 3 ? (:comp1, :comp2, :comp3, :alpha) : (:comp1, :alpha)
printargs = Array{Any}(uninitialized, 2, N)
printargs = Array{Any}(undef, 2, N)
for i = 1:N
printargs[1,i] = :(show(io, $(component[i])(c)))
chr = i < N ? ',' : ')'
Expand All @@ -23,7 +21,7 @@ for N = 1:4
end
end
for i = 1:N
printargs[1,i] = :(showcompact(io, $(component[i])(c)))
printargs[1,i] = :(show(IOContext(io, :compact => true), $(component[i])(c)))
end
@eval begin
function _showcompact(io::IO, c::Colorant{T,$N}) where T
Expand Down
6 changes: 3 additions & 3 deletions src/types.jl
Expand Up @@ -411,7 +411,7 @@ AGray32(g::AbstractGray, alpha = 1) = AGray32(gray(g), alpha)
# traits in the rest of this file are intended just for internal use

const color3types = map(s->getfield(ColorTypes,s),
filter(names(ColorTypes, false)) do s
filter(names(ColorTypes, all=false)) do s
isdefined(ColorTypes, s) || return false
t = getfield(ColorTypes, s)
isa(t, Type) && t <: Colorant && !isabstracttype(t) && length(fieldnames(t))>1
Expand Down Expand Up @@ -626,8 +626,8 @@ checkval(::Type{T}, a, b, c, d) where {T} = nothing

function throw_colorerror_(::Type{T}, values) where T<:Normed
io = IOBuffer()
showcompact(io, typemin(T)); Tmin = String(take!(io))
showcompact(io, typemax(T)); Tmax = String(take!(io))
show(IOContext(io, :compact=>true), typemin(T)); Tmin = String(take!(io))
show(IOContext(io, :compact=>true), typemax(T)); Tmax = String(take!(io))
bitstring = sizeof(T) == 1 ? "an 8-bit" : "a $(8*sizeof(T))-bit"
throw(ArgumentError("""
element type $T is $bitstring type representing $(2^(8*sizeof(T))) values from $Tmin to $Tmax,
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Expand Up @@ -61,7 +61,7 @@ tformat(x...) = join(string.(x), ", ")
@test @inferred(ccolor(Gray, Bool)) === Gray{Bool}
@test @inferred(ccolor(Gray, Int)) === Gray{N0f8}
# This tests the same thing as the last, but in a user-observable way
let a = Array{Gray}(uninitialized, 1)
let a = Array{Gray}(undef, 1)
a[1] = Gray(0)
a[1] = 1
@test a[1] === Gray(1)
Expand Down Expand Up @@ -207,11 +207,11 @@ for C in filter(T -> T <: AbstractRGB, ColorTypes.color3types)
end

ret = @test_throws ArgumentError RGB(255, 17, 48)
@test contains(ret.value.msg, tformat(255,17,48))
@test contains(ret.value.msg, "0-255")
@test occursin(tformat(255,17,48), ret.value.msg)
@test occursin("0-255", ret.value.msg)
ret = @test_throws ArgumentError RGB(256, 17, 48)
@test contains(ret.value.msg, tformat(256,17,48))
@test !contains(ret.value.msg, "0-255")
@test occursin(tformat(256,17,48), ret.value.msg)
@test !occursin("0-255", ret.value.msg)

@testset "Test some Gray stuff" begin
c = Gray(0.8)
Expand Down Expand Up @@ -383,11 +383,11 @@ show(iob, c)
c = RGBA{N0f8}(0.32218,0.14983,0.87819,0.99241)
show(iob, c)
@test String(take!(iob)) == "RGBA{N0f8}(0.322,0.149,0.878,0.992)"
showcompact(iob, c)
show(IOContext(iob, :compact => true), c)
@test String(take!(iob)) == "RGBA{N0f8}(0.322,0.149,0.878,0.992)"
show(iob, cf)
@test String(take!(iob)) == "RGB{Float32}(0.32218f0,0.14983f0,0.87819f0)"
showcompact(iob, cf)
show(IOContext(iob, :compact => true), cf)
@test String(take!(iob)) == "RGB{Float32}(0.32218,0.14983,0.87819)"
show(iob, Gray24(0.4))
@test String(take!(iob)) == "Gray24(0.4N0f8)"
Expand Down

0 comments on commit 4386189

Please sign in to comment.