From 5467e0e63c89512f79618f3ed530c2a807b1951b Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 16 Feb 2018 13:06:15 -0500 Subject: [PATCH] test fixes, news --- NEWS.md | 4 ++-- base/multimedia.jl | 14 +++++++------- test/show.jl | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index bddc6c6372fca..ac3785997b883 100644 --- a/NEWS.md +++ b/NEWS.md @@ -180,8 +180,8 @@ Language changes backslashes and the end of the literal while 2n+1 backslashes followed by a quote encodes n backslashes followed by a quote character ([#22926]). - * `reprmime(mime, x)` has been renamed to `repr(mime, x)`, and along with `repr(x)` it - now also accepts zero or more `:symbol=>value` pairs specifying `IOContext` attributes. + * `reprmime(mime, x)` has been renamed to `repr(mime, x)`, and along with `repr(x)` + and `sprint` it now accepts an optional `context` keyword for `IOContext` attributes. `stringmime` has been moved to the Base64 stdlib package ([#25990]). * The syntax `(x...)` for constructing a tuple is deprecated; use `(x...,)` instead ([#24452]). diff --git a/base/multimedia.jl b/base/multimedia.jl index 3049bc8e7e1db..d988d4da2e5db 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -120,14 +120,14 @@ _textrepr(m::MIME, x, context) = String(__binrepr(m, x, context)) _textrepr(::MIME, x::AbstractString, context) = x _textrepr(m::MIME"text/plain", x::AbstractString, context) = String(__binrepr(m, x, context)) -function __binrepr(m::MIME, x, ::Nothing) - s = IOBuffer() - show(s, m, x) - take!(s) -end + function __binrepr(m::MIME, x, context) - s = IOBuffer(sizehint=sizehint) - show(IOContext(s, context), m, x) + s = IOBuffer() + if context === nothing + show(s, m, x) + else + show(IOContext(s, context), m, x) + end take!(s) end _binrepr(m::MIME, x, context) = __binrepr(m, x, context) diff --git a/test/show.jl b/test/show.jl index e0e793cd9d175..d7835c8a61a96 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1163,7 +1163,7 @@ end @test repr("text/plain", "string") == "\"string\"" @test repr("image/png", UInt8[2,3,4,7]) == UInt8[2,3,4,7] @test repr("text/plain", 3.141592653589793) == "3.141592653589793" - @test repr("text/plain", 3.141592653589793, :compact=>true) == "3.14159" + @test repr("text/plain", 3.141592653589793, context=:compact=>true) == "3.14159" @test repr("text/plain", context=:compact=>true) == "\"text/plain\"" @test repr(MIME("text/plain"), context=:compact=>true) == "MIME type text/plain" end