diff --git a/base/Enums.jl b/base/Enums.jl index 39581d411f758..ba1073cd36f72 100644 --- a/base/Enums.jl +++ b/base/Enums.jl @@ -85,14 +85,14 @@ macro enum(T,syms...) let insts = ntuple(i->$(esc(typename))($values[i]), $(length(vals))) Base.instances(::Type{$(esc(typename))}) = insts end - function Base.print(io::IO,x::$(esc(typename))) + function Base.print(io::IO, x::$(esc(typename))) for (sym, i) in $vals if i == Int32(x) print(io, sym); break end end end - function Base.show(io::IO,x::$(esc(typename))) + function Base.show(io::IO, x::$(esc(typename))) if get(io, :compact, false) print(io, x) else @@ -101,16 +101,15 @@ macro enum(T,syms...) print(io, " = ", Int(x)) end end - function Base.show(io::IO,t::Type{$(esc(typename))}) - if get(io, :multiline, false) - print(io, "Enum ") - Base.show_datatype(io, t) - print(io, ":") - for (sym, i) in $vals - print(io, "\n", sym, " = ", i) - end - else - Base.show_datatype(io, t) + function Base.show(io::IO, t::Type{$(esc(typename))}) + Base.show_datatype(io, t) + end + function Base.show(io::IO, ::MIME"text/plain", t::Type{$(esc(typename))}) + print(io, "Enum ") + Base.show_datatype(io, t) + print(io, ":") + for (sym, i) in $vals + print(io, "\n", sym, " = ", i) end end end diff --git a/base/REPL.jl b/base/REPL.jl index 977fb156bdfc4..deebc606df6a5 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -108,10 +108,10 @@ end ==(a::REPLDisplay, b::REPLDisplay) = a.repl === b.repl -function display(d::REPLDisplay, ::MIME"text/plain", x) +function display(d::REPLDisplay, mime::MIME"text/plain", x) io = outstream(d.repl) Base.have_color && write(io, answer_color(d.repl)) - show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x) + show(IOContext(io, :limit => true), mime, x) println(io) end display(d::REPLDisplay, x) = display(d, MIME("text/plain"), x) diff --git a/base/deprecated.jl b/base/deprecated.jl index b22c1a3cc6523..8e59e53e1269e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -788,6 +788,19 @@ function symperm{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, pinv::Vector{Ti}) "Pkg.add(\"SuiteSparse\") to install SuiteSparse on Julia v0.5.")) end +# needs to be a macro so that we can use ::@mime(s) in type declarations +eval(Multimedia, quote +export @MIME +macro MIME(s) + Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.") + if isa(s,AbstractString) + :(MIME{$(Expr(:quote, Symbol(s)))}) + else + :(MIME{Symbol($s)}) + end +end +end) + # During the 0.5 development cycle, do not add any deprecations below this line # To be deprecated in 0.6 diff --git a/base/dict.jl b/base/dict.jl index 0d5dbe321b642..7acee007133d6 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -49,91 +49,34 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…") end function show{K,V}(io::IO, t::Associative{K,V}) - recur_io = IOContext(io, SHOWN_SET=t, multiline=false) + recur_io = IOContext(io, :SHOWN_SET => t) limit::Bool = get(io, :limit, false) - compact = !get(io, :multiline, false) if !haskey(io, :compact) - recur_io = IOContext(recur_io, compact=true) + recur_io = IOContext(recur_io, :compact => true) end - if compact - # show in a Julia-syntax-like form: Dict(k=>v, ...) - if isempty(t) - print(io, typeof(t), "()") - else - if isleaftype(K) && isleaftype(V) - print(io, typeof(t).name) - else - print(io, typeof(t)) - end - print(io, '(') - if !show_circular(io, t) - first = true - n = 0 - for pair in t - first || print(io, ',') - first = false - show(recur_io, pair) - n+=1 - limit && n >= 10 && (print(io, "…"); break) - end - end - print(io, ')') - end - return - end - - # Otherwise show more descriptively, with one line per key/value pair - print(io, summary(t)) - isempty(t) && return - print(io, ":\n ") - show_circular(io, t) && return - if limit - sz = displaysize(io) - rows, cols = sz[1] - 3, sz[2] - rows < 2 && (print(io, " …"); return) - cols < 12 && (cols = 12) # Minimum widths of 2 for key, 4 for value - cols -= 6 # Subtract the widths of prefix " " separator " => " - rows -= 2 # Subtract the summary and final ⋮ continuation lines - - # determine max key width to align the output, caching the strings - ks = Array{AbstractString}(min(rows, length(t))) - vs = Array{AbstractString}(min(rows, length(t))) - keylen = 0 - vallen = 0 - for (i, (k, v)) in enumerate(t) - i > rows && break - ks[i] = sprint(0, show, k, env=recur_io) - vs[i] = sprint(0, show, v, env=recur_io) - keylen = clamp(length(ks[i]), keylen, cols) - vallen = clamp(length(vs[i]), vallen, cols) - end - if keylen > max(div(cols, 2), cols - vallen) - keylen = max(cld(cols, 3), cols - vallen) - end - else - rows = cols = 0 - end - - first = true - for (i, (k, v)) in enumerate(t) - first || print(io, "\n ") - first = false - limit && i > rows && (print(io, rpad("⋮", keylen), " => ⋮"); break) - if limit - key = rpad(_truncate_at_width_or_chars(ks[i], keylen, "\r\n"), keylen) + # show in a Julia-syntax-like form: Dict(k=>v, ...) + if isempty(t) + print(io, typeof(t), "()") + else + if isleaftype(K) && isleaftype(V) + print(io, typeof(t).name) else - key = sprint(0, show, k, env=recur_io) + print(io, typeof(t)) end - print(recur_io, key) - print(io, " => ") - - if limit - val = _truncate_at_width_or_chars(vs[i], cols - keylen, "\r\n") - print(io, val) - else - show(recur_io, v) + print(io, '(') + if !show_circular(io, t) + first = true + n = 0 + for pair in t + first || print(io, ',') + first = false + show(recur_io, pair) + n+=1 + limit && n >= 10 && (print(io, "…"); break) + end end + print(io, ')') end end @@ -147,38 +90,7 @@ end summary{T<:Union{KeyIterator,ValueIterator}}(iter::T) = string(T.name, " for a ", summary(iter.dict)) -function show(io::IO, iter::Union{KeyIterator,ValueIterator}) - if !get(io, :multiline, false) - return show(io, collect(iter)) - end - print(io, summary(iter)) - isempty(iter) && return - print(io, ". ", isa(iter,KeyIterator) ? "Keys" : "Values", ":") - limit::Bool = get(io, :limit, false) - if limit - sz = displaysize(io) - rows, cols = sz[1] - 3, sz[2] - rows < 2 && (print(io, " …"); return) - cols < 4 && (cols = 4) - cols -= 2 # For prefix " " - rows -= 2 # For summary and final ⋮ continuation lines - else - rows = cols = 0 - end - - for (i, v) in enumerate(iter) - print(io, "\n ") - limit && i >= rows && (print(io, "⋮"); break) - - if limit - str = sprint(0, show, v, env=io) - str = _truncate_at_width_or_chars(str, cols, "\r\n") - print(io, str) - else - show(io, v) - end - end -end +show(io::IO, iter::Union{KeyIterator,ValueIterator}) = show(io, collect(iter)) length(v::Union{KeyIterator,ValueIterator}) = length(v.dict) isempty(v::Union{KeyIterator,ValueIterator}) = isempty(v.dict) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 1b6452b2a4373..dfa3aae1d44c7 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -168,15 +168,12 @@ svdfact(M::Bidiagonal; thin::Bool=true) = svdfact!(copy(M),thin=thin) #################### function show(io::IO, M::Bidiagonal) - if get(io, :multiline, false) - Base.showarray(io, M) - else - println(io, summary(M), ":") - print(io, " diag:") - print_matrix(io, (M.dv)') - print(io, M.isupper?"\n super:":"\n sub:") - print_matrix(io, (M.ev)') - end + # TODO: make this readable and one-line + println(io, summary(M), ":") + print(io, " diag:") + print_matrix(io, (M.dv)') + print(io, M.isupper?"\n super:":"\n sub:") + print_matrix(io, (M.ev)') end size(M::Bidiagonal) = (length(M.dv), length(M.dv)) diff --git a/base/multimedia.jl b/base/multimedia.jl index 416b4df051257..45b827e66d859 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -3,7 +3,7 @@ module Multimedia export Display, display, pushdisplay, popdisplay, displayable, redisplay, - MIME, @MIME, @MIME_str, reprmime, stringmime, istextmime, + MIME, @MIME_str, reprmime, stringmime, istextmime, mimewritable, TextDisplay ########################################################################### @@ -18,16 +18,6 @@ MIME(s) = MIME{Symbol(s)}() show{mime}(io::IO, ::MIME{mime}) = print(io, "MIME type ", string(mime)) print{mime}(io::IO, ::MIME{mime}) = print(io, mime) -# needs to be a macro so that we can use ::@mime(s) in type declarations -macro MIME(s) - Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.") - if isa(s,AbstractString) - :(MIME{$(Expr(:quote, Symbol(s)))}) - else - :(MIME{Symbol($s)}) - end -end - macro MIME_str(s) :(MIME{$(Expr(:quote, Symbol(s)))}) end diff --git a/base/range.jl b/base/range.jl index 9dfe9a394060d..58ec756d1b078 100644 --- a/base/range.jl +++ b/base/range.jl @@ -236,25 +236,13 @@ linspace(start::Real, stop::Real, len::Real=50) = linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len) function show(io::IO, r::LinSpace) - if get(io, :multiline, false) - # show for linspace, e.g. - # linspace(1,3,7) - # 7-element LinSpace{Float64}: - # 1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0 - print(io, summary(r)) - if !isempty(r) - println(io, ":") - print_range(io, r) - end - else - print(io, "linspace(") - show(io, first(r)) - print(io, ',') - show(io, last(r)) - print(io, ',') - show(io, length(r)) - print(io, ')') - end + print(io, "linspace(") + show(io, first(r)) + print(io, ',') + show(io, last(r)) + print(io, ',') + show(io, length(r)) + print(io, ')') end """ @@ -497,9 +485,7 @@ function getindex{T}(r::LinSpace{T}, s::OrdinalRange) return linspace(vfirst, vlast, sl) end -function show(io::IO, r::Range) - print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r))) -end +show(io::IO, r::Range) = print(io, repr(first(r)), ':', repr(step(r)), ':', repr(last(r))) show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r))) =={T<:Range}(r::T, s::T) = (first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)) diff --git a/base/replutil.jl b/base/replutil.jl index c1ed0f2543953..cf8a83dea01c9 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -3,6 +3,139 @@ # fallback text/plain representation of any type: show(io::IO, ::MIME"text/plain", x) = show(io, x) +# multiline show functions for types defined before multimedia.jl: +function show(io::IO, ::MIME"text/plain", iter::Union{KeyIterator,ValueIterator}) + print(io, summary(iter)) + isempty(iter) && return + print(io, ". ", isa(iter,KeyIterator) ? "Keys" : "Values", ":") + limit::Bool = get(io, :limit, false) + if limit + sz = displaysize(io) + rows, cols = sz[1] - 3, sz[2] + rows < 2 && (print(io, " …"); return) + cols < 4 && (cols = 4) + cols -= 2 # For prefix " " + rows -= 2 # For summary and final ⋮ continuation lines + else + rows = cols = 0 + end + + for (i, v) in enumerate(iter) + print(io, "\n ") + limit && i >= rows && (print(io, "⋮"); break) + + if limit + str = sprint(0, show, v, env=io) + str = _truncate_at_width_or_chars(str, cols, "\r\n") + print(io, str) + else + show(io, v) + end + end +end + +function show{K,V}(io::IO, ::MIME"text/plain", t::Associative{K,V}) + # show more descriptively, with one line per key/value pair + recur_io = IOContext(io, :SHOWN_SET => t) + limit::Bool = get(io, :limit, false) + if !haskey(io, :compact) + recur_io = IOContext(recur_io, compact=true) + end + + print(io, summary(t)) + isempty(t) && return + print(io, ":\n ") + show_circular(io, t) && return + if limit + sz = displaysize(io) + rows, cols = sz[1] - 3, sz[2] + rows < 2 && (print(io, " …"); return) + cols < 12 && (cols = 12) # Minimum widths of 2 for key, 4 for value + cols -= 6 # Subtract the widths of prefix " " separator " => " + rows -= 2 # Subtract the summary and final ⋮ continuation lines + + # determine max key width to align the output, caching the strings + ks = Array{AbstractString}(min(rows, length(t))) + vs = Array{AbstractString}(min(rows, length(t))) + keylen = 0 + vallen = 0 + for (i, (k, v)) in enumerate(t) + i > rows && break + ks[i] = sprint(0, show, k, env=recur_io) + vs[i] = sprint(0, show, v, env=recur_io) + keylen = clamp(length(ks[i]), keylen, cols) + vallen = clamp(length(vs[i]), vallen, cols) + end + if keylen > max(div(cols, 2), cols - vallen) + keylen = max(cld(cols, 3), cols - vallen) + end + else + rows = cols = 0 + end + + first = true + for (i, (k, v)) in enumerate(t) + first || print(io, "\n ") + first = false + limit && i > rows && (print(io, rpad("⋮", keylen), " => ⋮"); break) + + if limit + key = rpad(_truncate_at_width_or_chars(ks[i], keylen, "\r\n"), keylen) + else + key = sprint(0, show, k, env=recur_io) + end + print(recur_io, key) + print(io, " => ") + + if limit + val = _truncate_at_width_or_chars(vs[i], cols - keylen, "\r\n") + print(io, val) + else + show(recur_io, v) + end + end +end + +function show(io::IO, ::MIME"text/plain", f::Function) + ft = typeof(f) + mt = ft.name.mt + if isa(f, Core.Builtin) + print(io, mt.name, " (built-in function)") + else + name = mt.name + isself = isdefined(ft.name.module, name) && + ft == typeof(getfield(ft.name.module, name)) + n = length(mt) + m = n==1 ? "method" : "methods" + ns = isself ? string(name) : string("(::", name, ")") + what = startswith(ns, '@') ? "macro" : "generic function" + print(io, ns, " (", what, " with $n $m)") + end +end + +function show(io::IO, ::MIME"text/plain", r::LinSpace) + # show for linspace, e.g. + # linspace(1,3,7) + # 7-element LinSpace{Float64}: + # 1.0,1.33333,1.66667,2.0,2.33333,2.66667,3.0 + print(io, summary(r)) + if !isempty(r) + println(io, ":") + print_range(io, r) + end +end + +function show(io::IO, ::MIME"text/plain", t::Task) + show(io, t) + if t.state == :failed + println(io) + showerror(io, CapturedException(t.result, t.backtrace)) + end +end + +show(io::IO, ::MIME"text/plain", X::AbstractArray) = showarray(io, X, false) +show(io::IO, ::MIME"text/plain", r::Range) = show(io, r) # always use the compact form for printing ranges + # showing exception objects as descriptive error messages diff --git a/base/show.jl b/base/show.jl index 1f1f9fb0c0f4c..eef8d1eb8a012 100644 --- a/base/show.jl +++ b/base/show.jl @@ -101,7 +101,7 @@ function show_default(io::IO, x::ANY) nf = nfields(t) if nf != 0 || t.size==0 if !show_circular(io, x) - recur_io = IOContext(IOContext(io, :SHOWN_SET=>x), :multiline=>false) + recur_io = IOContext(io, :SHOWN_SET => x) for i=1:nf f = fieldname(t, i) if !isdefined(x, f) @@ -141,25 +141,10 @@ end function show(io::IO, f::Function) ft = typeof(f) mt = ft.name.mt - if get(io, :multiline, false) - if isa(f, Core.Builtin) - print(io, mt.name, " (built-in function)") - else - name = mt.name - isself = isdefined(ft.name.module, name) && - ft == typeof(getfield(ft.name.module, name)) - n = length(mt) - m = n==1 ? "method" : "methods" - ns = isself ? string(name) : string("(::", name, ")") - what = startswith(ns, '@') ? "macro" : "generic function" - print(io, ns, " (", what, " with $n $m)") - end + if !isdefined(mt, :module) || is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main + print(io, mt.name) else - if !isdefined(mt, :module) || is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main - print(io, mt.name) - else - print(io, mt.module, ".", mt.name) - end + print(io, mt.module, ".", mt.name) end end @@ -301,9 +286,9 @@ function show_delim_array(io::IO, itr::Union{AbstractArray,SimpleVector}, op, de delim_one, i1=first(linearindices(itr)), l=last(linearindices(itr))) print(io, op) if !show_circular(io, itr) - recur_io = IOContext(io, SHOWN_SET=itr, multiline=false) + recur_io = IOContext(io, :SHOWN_SET => itr) if !haskey(io, :compact) - recur_io = IOContext(recur_io, compact=true) + recur_io = IOContext(recur_io, :compact => true) end newline = true first = true @@ -1534,10 +1519,9 @@ function print_matrix_repr(io, X::AbstractArray) print(io, "]") end -show(io::IO, X::AbstractArray) = showarray(io, X) +show(io::IO, X::AbstractArray) = showarray(io, X, true) -function showarray(io::IO, X::AbstractArray) - repr = !get(io, :multiline, false) +function showarray(io::IO, X::AbstractArray, repr::Bool) if repr && ndims(X) == 1 return show_vector(io, X, "[", "]") end @@ -1590,18 +1574,9 @@ end showcompact(x) = showcompact(STDOUT, x) function showcompact(io::IO, x) if get(io, :compact, false) - if !get(io, :multiline, false) - show(io, x) - else - show(IOContext(io, :multiline => false), x) - end + show(io, x) else - if !get(io, :multiline, false) - show(IOContext(io, :compact => true), x) - else - show(IOContext(IOContext(io, :compact => true), - :multiline => false), x) - end + show(IOContext(io, :compact => true), x) end end diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index f596b26d40ae0..9cb721ec075b0 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -1093,6 +1093,10 @@ function showfactor(io::IO, F::Factor) @printf(io, "nnz: %13d\n", nnz(F)) end +# getindex not defined for these, so don't use the normal array printer +show(io::IO, ::MIME"text/plain", FC::FactorComponent) = show(io, FC) +show(io::IO, ::MIME"text/plain", F::Factor) = show(io, F) + isvalid(A::Dense) = check_dense(A) isvalid(A::Sparse) = check_sparse(A) isvalid(A::Factor) = check_factor(A) @@ -1115,6 +1119,7 @@ function size(F::Factor, i::Integer) end return 1 end +size(F::Factor) = (size(F, 1), size(F, 2)) linearindexing(::Dense) = LinearFast() diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 7e3bac45a3594..effbe9813afc7 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -76,9 +76,17 @@ convenient iterating over a sparse matrix : """ nzrange(S::SparseMatrixCSC, col::Integer) = S.colptr[col]:(S.colptr[col+1]-1) +function Base.show(io::IO, ::MIME"text/plain", S::SparseMatrixCSC) + print(io, S.m, "×", S.n, " sparse matrix with ", nnz(S), " ", eltype(S), " nonzero entries") + if nnz(S) != 0 + print(io, ":") + show(io, S) + end +end + function Base.show(io::IO, S::SparseMatrixCSC) - if get(io, :multiline, false) || (nnz(S) == 0) - print(io, S.m, "×", S.n, " sparse matrix with ", nnz(S), " ", eltype(S), " nonzero entries", nnz(S) == 0 ? "" : ":") + if nnz(S) == 0 + return show(io, MIME("text/plain"), S) end limit::Bool = get(io, :limit, false) @@ -91,9 +99,9 @@ function Base.show(io::IO, S::SparseMatrixCSC) pad = ndigits(max(S.m,S.n)) k = 0 sep = "\n\t" - io = IOContext(io, multiline=false) + io = IOContext(io) if !haskey(io, :compact) - io = IOContext(io, compact=true) + io = IOContext(io, :compact => true) end for col = 1:S.n, k = S.colptr[col] : (S.colptr[col+1]-1) if k < half_screen_rows || k > nnz(S)-half_screen_rows diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 4bbad1ca948f7..13a35fa33f494 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -607,23 +607,25 @@ getindex(x::AbstractSparseVector, ::Colon) = copy(x) ### show and friends +function show(io::IO, ::MIME"text/plain", x::AbstractSparseVector) + println(io, summary(x)) + show(io, x) +end + function show(io::IO, x::AbstractSparseVector) + # TODO: make this a one-line form n = length(x) nzind = nonzeroinds(x) nzval = nonzeros(x) xnnz = length(nzind) - if get(io, :multiline, false) - println(io, summary(x)) - end - limit::Bool = get(io, :limit, false) half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) pad = ndigits(n) sep = "\n\t" - io = IOContext(io, multiline=false) + io = IOContext(io) if !haskey(io, :compact) - io = IOContext(io, compact=true) + io = IOContext(io, :compact => true) end for k = 1:length(nzind) if k < half_screen_rows || k > xnnz - half_screen_rows diff --git a/base/task.jl b/base/task.jl index 09859decd2cae..00d546f705b04 100644 --- a/base/task.jl +++ b/base/task.jl @@ -48,12 +48,6 @@ end function show(io::IO, t::Task) print(io, "Task ($(t.state)) @0x$(hex(convert(UInt, pointer_from_objref(t)), Sys.WORD_SIZE>>2))") - if get(io, :multiline, false) - if t.state == :failed - println(io) - showerror(io, CapturedException(t.result, t.backtrace)) - end - end end macro task(ex) diff --git a/test/dict.jl b/test/dict.jl index e9aa4241cbb6c..c0cde55fcee63 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -268,8 +268,8 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), for cols in (12, 40, 80), rows in (2, 10, 24) # Ensure output is limited as requested s = IOBuffer() - io = Base.IOContext(s, limit=true, displaysize=(rows, cols), multiline=true) - Base.show(io, d) + io = Base.IOContext(s, limit=true, displaysize=(rows, cols)) + Base.show(io, MIME("text/plain"), d) out = split(takebuf_string(s),'\n') for line in out[2:end] @test strwidth(line) <= cols @@ -278,8 +278,8 @@ for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), for f in (keys, values) s = IOBuffer() - io = Base.IOContext(s, limit=true, displaysize=(rows, cols), multiline=true) - Base.show(io, f(d)) + io = Base.IOContext(s, limit=true, displaysize=(rows, cols)) + Base.show(io, MIME("text/plain"), f(d)) out = split(takebuf_string(s),'\n') for line in out[2:end] @test strwidth(line) <= cols @@ -311,9 +311,9 @@ end type Alpha end Base.show(io::IO, ::Alpha) = print(io,"α") let sbuff = IOBuffer(), - io = Base.IOContext(sbuff, limit=true, displaysize=(10, 20), multiline=true) + io = Base.IOContext(sbuff, limit=true, displaysize=(10, 20)) - Base.show(io, Dict(Alpha()=>1)) + Base.show(io, MIME("text/plain"), Dict(Alpha()=>1)) @test !contains(String(sbuff), "…") @test endswith(String(sbuff), "α => 1") end diff --git a/test/offsetarray.jl b/test/offsetarray.jl index caf19f96b77f6..790edde60d350 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -178,7 +178,7 @@ str = takebuf_string(io) show(io, S) str = takebuf_string(io) @test str == "[1 3; 2 4]" -show(IOContext(io, multiline=true), A) +show(io, MIME("text/plain"), A) strs = split(strip(takebuf_string(io)), '\n') @test strs[2] == " 1 3" @test strs[3] == " 2 4" @@ -188,7 +188,7 @@ str = takebuf_string(io) show(io, parent(v)) @test str == takebuf_string(io) function cmp_showf(printfunc, io, A) - ioc = IOContext(io, limit=true, multiline=true, compact=true) + ioc = IOContext(io, limit=true, compact=true) printfunc(ioc, A) str1 = takebuf_string(io) printfunc(ioc, parent(A)) diff --git a/test/ranges.jl b/test/ranges.jl index 8b04717e6df21..5b23818ce56ee 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -569,7 +569,7 @@ end # stringmime/show should display the range or linspace nicely # to test print_range in range.jl -replstrmime(x) = sprint((io,x) -> show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x), x) +replstrmime(x) = sprint((io,x) -> show(IOContext(io, limit=true), MIME("text/plain"), x), x) @test replstrmime(1:4) == "1:4" @test stringmime("text/plain", 1:4) == "1:4" @test stringmime("text/plain", linspace(1,5,7)) == "7-element LinSpace{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0" diff --git a/test/replutil.jl b/test/replutil.jl index 40d69ef76f15f..ac2f18fc9c9cb 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -354,10 +354,10 @@ end # Issue #14684: `display` should prints associative types in full. let d = Dict(1 => 2, 3 => 45) - buf = IOContext(IOBuffer(), multiline=true) + buf = IOBuffer() td = TextDisplay(buf) display(td, d) - result = String(td.io.io) + result = String(td.io) @test contains(result, summary(d)) diff --git a/test/show.jl b/test/show.jl index ff9d1ec960d92..81952479e88ec 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -replstr(x) = sprint((io,x) -> show(IOContext(io, multiline=true, limit=true), MIME("text/plain"), x), x) +replstr(x) = sprint((io,x) -> show(IOContext(io, limit=true), MIME("text/plain"), x), x) @test replstr(Array{Any}(2)) == "2-element Array{Any,1}:\n #undef\n #undef" @test replstr(Array{Any}(2,2)) == "2×2 Array{Any,2}:\n #undef #undef\n #undef #undef" @@ -486,10 +486,6 @@ let io = IOBuffer() x = [1, 2] showcompact(io, x) @test takebuf_string(io) == "[1,2]" - showcompact(IOContext(io, :multiline=>true), x) - @test takebuf_string(io) == "[1,2]" showcompact(IOContext(io, :compact=>true), x) @test takebuf_string(io) == "[1,2]" - showcompact(IOContext(IOContext(io, :compact=>true), :multiline=>true), x) - @test takebuf_string(io) == "[1,2]" end diff --git a/test/sparsedir/cholmod.jl b/test/sparsedir/cholmod.jl index 6f4ca625c1f05..9b426481b65fe 100644 --- a/test/sparsedir/cholmod.jl +++ b/test/sparsedir/cholmod.jl @@ -591,7 +591,12 @@ Dp = spdiagm(dp) sparse(cholfact(sparse(Float64[ 10 1 1 1; 1 10 0 0; 1 0 10 0; 1 0 0 10]))); gc() # Issue 11747 - Wrong show method defined for FactorComponent -Base.show(IOBuffer(), MIME"text/plain"(), cholfact(sparse(Float64[ 10 1 1 1; 1 10 0 0; 1 0 10 0; 1 0 0 10]))[:L]) +let v = cholfact(sparse(Float64[ 10 1 1 1; 1 10 0 0; 1 0 10 0; 1 0 0 10]))[:L] + for s in (sprint(show, MIME("text/plain"), v), sprint(show, v)) + @test contains(s, "method: simplicial") + @test !contains(s, "#undef") + end +end # Element promotion and type inference @inferred cholfact(As)\ones(Int, size(As, 1))