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 dfa2e49
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -3,9 +3,9 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
after_success:
- julia -e 'if VERSION >= v"0.6.0-dev.565" cd(Pkg.dir("ColorTypes")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder()); end'
- julia -e 'cd(Pkg.dir("ColorTypes")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
3 changes: 1 addition & 2 deletions REQUIRE
@@ -1,3 +1,2 @@
julia 0.6
Compat 0.50.0
julia 0.7-alpha
FixedPointNumbers 0.3.0
6 changes: 1 addition & 5 deletions src/ColorTypes.jl
Expand Up @@ -5,15 +5,11 @@ module ColorTypes
using FixedPointNumbers
using Base: @pure

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

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
4 changes: 1 addition & 3 deletions src/operations.jl
Expand Up @@ -4,9 +4,7 @@ hash(c::TransparentGray, hx::UInt) = hash(alpha(c), hash(gray(c), hx))
hash(c::AbstractRGB, hx::UInt) = hash(blue(c), hash(green(c), hash(red(c), hx)))
hash(c::TransparentRGB, hx::UInt) = hash(alpha(c), hash(blue(c), hash(green(c), hash(red(c), hx))))

if VERSION >= v"0.6.0-dev.2680"
Compat.adjoint(c::Colorant) = c
end
Base.adjoint(c::Colorant) = c

# gamut{min,max}
gamutmax(::Type{T}) where {T<:HSV} = (360,1,1)
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
8 changes: 4 additions & 4 deletions src/traits.jl
Expand Up @@ -95,7 +95,7 @@ eltype(c::Colorant) = eltype(typeof(c))

# eltypes_supported(Colorant{T<:X}) -> T<:X (pre 0.6) or X (post 0.6)
@pure eltypes_supported(::Type{C}) where {C<:Colorant} =
parameter_upper_bound(base_colorant_type(C), 1)
Base.parameter_upper_bound(base_colorant_type(C), 1)

eltypes_supported(c::Colorant) = eltypes_supported(typeof(c))

Expand Down Expand Up @@ -128,7 +128,7 @@ length(::Type{C}) where C<:(Colorant{T,N} where T) where N = N
# applicable.
_color_type(::Type{TC}) where TC<:(TransparentColor{C, T, N} where T where N) where C = C
color_type(::Type{TC}) where TC<:TransparentColor =
isa(TC, UnionAll) ? parameter_upper_bound(TC, 1) : _color_type(TC)
isa(TC, UnionAll) ? Base.parameter_upper_bound(TC, 1) : _color_type(TC)
color_type(::Type{TC}) where TC<:(TransparentColor{C, T, N} where T where N) where C = C

@pure color_type(::Type{C}) where {C<:AlphaColor} = color_type(supertype(C))
Expand All @@ -153,7 +153,7 @@ base_color_type(::Type{C}) where {C<:Colorant} = base_colorant_type(color_type(C
base_color_type(c::Colorant) = base_color_type(typeof(c))
base_color_type(x::Number) = Gray

@pure basetype(T) = typename(T).wrapper
@pure basetype(T) = Base.typename(T).wrapper
base_colorant_type(::Type{C}) where {C<:Colorant} = basetype(C)

"""
Expand All @@ -173,7 +173,7 @@ and the easiest to use:
base_colorant_type(c::Colorant) = base_colorant_type(typeof(c))

colorant_string(::Type{Union{}}) = "Union{}"
colorant_string(::Type{C}) where {C<:Colorant} = string(Compat.nameof(C))
colorant_string(::Type{C}) where {C<:Colorant} = string(nameof(C))
function colorant_string_with_eltype(::Type{C}) where {C<:Colorant}
io = IOBuffer()
colorant_string_with_eltype(io, C)
Expand Down
8 changes: 4 additions & 4 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 @@ -561,7 +561,7 @@ for (C, acol, cola) in [(DIN99d, :ADIN99d, :DIN99dA),
cfn = Expr(:tuple, colorfields(C)...)
elty = eltype_default(C)
ub = eltype_ub(C)
Csym = Compat.nameof(Base.unwrap_unionall(C))
Csym = nameof(Base.unwrap_unionall(C))
@eval @make_constructors $Csym $fn $elty
@eval @make_alpha $Csym $acol $cola $fn $cfn $ub $elty
end
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
16 changes: 8 additions & 8 deletions test/runtests.jl
@@ -1,5 +1,5 @@
using ColorTypes, FixedPointNumbers
using Compat, Compat.Test
using Test

@test isempty(detect_ambiguities(ColorTypes, Base, Core))

Expand Down 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 dfa2e49

Please sign in to comment.