Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: move stringmime to Base64, rename reprmime -> repr #25990

Merged
merged 14 commits into from
Feb 17, 2018
Prev Previous commit
Next Next commit
stringmime(text/plain, x) can be replaced with repr(text/plain, x)
  • Loading branch information
stevengj committed Feb 16, 2018
commit 958812359933aa37c9bb0afed3509449ea14ec3b
4 changes: 2 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docstring_startswith(d1::DocStr, d2) = docstring_startswith(parsedoc(d1), d2)

@doc "Doc abstract type"
abstract type C74685{T,N} <: AbstractArray{T,N} end
@test stringmime("text/plain", Docs.doc(C74685))==" Doc abstract type\n"
@test repr("text/plain", Docs.doc(C74685))==" Doc abstract type\n"
@test string(Docs.doc(C74685))=="Doc abstract type\n"

macro macro_doctest() end
Expand Down Expand Up @@ -559,7 +559,7 @@ REPL.docsearch(haystack::LazyHelp, needle) = REPL.docsearch(haystack.text, needl
end

let d = @doc(I15424.LazyHelp)
@test stringmime("text/plain", d) == "LazyHelp\nLazyHelp(text)\n"
@test repr("text/plain", d) == "LazyHelp\nLazyHelp(text)\n"
end

# Issue #13385.
Expand Down
8 changes: 4 additions & 4 deletions test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ let err_str,
err_str = @except_str randn(1)() MethodError
@test contains(err_str, "MethodError: objects of type Array{Float64,1} are not callable")
end
@test stringmime("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 0 methods)"
@test contains(stringmime("text/plain", getfield(Base, Symbol("@doc"))), r"^@doc \(macro with \d+ method[s]?\)$")
@test repr("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 0 methods)"
@test contains(repr("text/plain", getfield(Base, Symbol("@doc"))), r"^@doc \(macro with \d+ method[s]?\)$")

method_defs_lineno = @__LINE__() + 1
Base.Symbol() = throw(ErrorException("1"))
Expand Down Expand Up @@ -356,8 +356,8 @@ let err_str,
"@doc(__source__::LineNumberNode, __module__::Module, x...) in Core at boot.jl:")
@test startswith(sprint(show, which(FunctionLike(), Tuple{})),
"(::$(curmod_prefix)FunctionLike)() in $curmod_str at $sp:$(method_defs_lineno + 7)")
@test stringmime("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 1 method)"
@test stringmime("text/plain", Core.arraysize) == "arraysize (built-in function)"
@test repr("text/plain", FunctionLike()) == "(::$(curmod_prefix)FunctionLike) (generic function with 1 method)"
@test repr("text/plain", Core.arraysize) == "arraysize (built-in function)"

err_str = @except_stackframe Symbol() ErrorException
@test err_str == "Symbol() at $sn:$(method_defs_lineno + 0)"
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ if Sys.iswindows()
end
end

let optstring = stringmime(MIME("text/plain"), Base.JLOptions())
let optstring = repr("text/plain", Base.JLOptions())
@test startswith(optstring, "JLOptions(\n")
@test !contains(optstring, "Ptr")
@test endswith(optstring, "\n)")
Expand Down
20 changes: 10 additions & 10 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -903,22 +903,22 @@ end
@test i == 7
end

@testset "stringmime/repr" begin
# stringmime/show should display the range nicely
@testset "repr" begin
# repr/show should display the range nicely
# to test print_range in range.jl
replstrmime(x) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80)), MIME("text/plain"), x), x)
@test replstrmime(1:4) == "1:4"
@test stringmime("text/plain", 1:4) == "1:4"
@test stringmime("text/plain", range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test stringmime("text/plain", LinRange{Float64}(1,5,7)) == "7-element LinRange{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
replrepr(x) = repr("text/plain", x; context=IOContext(STDOUT, :limit=>true, :displaysize=>(24, 80)))
@test replrepr(1:4) == "1:4"
@test repr("text/plain", 1:4) == "1:4"
@test repr("text/plain", range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr("text/plain", LinRange{Float64}(1,5,7)) == "7-element LinRange{Float64}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
@test repr(range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr(LinRange{Float64}(1,5,7)) == "range(1.0, stop=5.0, length=7)"
@test replstrmime(0:100.) == "0.0:1.0:100.0"
@test replrepr(0:100.) == "0.0:1.0:100.0"
# next is to test a very large range, which should be fast because print_range
# only examines spacing of the left and right edges of the range, sufficient
# to cover the designated screen size.
@test replstrmime(range(0, stop=100, length=10000)) == "0.0:0.010001000100010001:100.0"
@test replstrmime(LinRange{Float64}(0,100, 10000)) == "10000-element LinRange{Float64}:\n 0.0,0.010001,0.020002,0.030003,0.040004,…,99.95,99.96,99.97,99.98,99.99,100.0"
@test replrepr(range(0, stop=100, length=10000)) == "0.0:0.010001000100010001:100.0"
@test replrepr(LinRange{Float64}(0,100, 10000)) == "10000-element LinRange{Float64}:\n 0.0,0.010001,0.020002,0.030003,0.040004,…,99.95,99.96,99.97,99.98,99.99,100.0"

@test sprint(show, UnitRange(1, 2)) == "1:2"
@test sprint(show, StepRange(1, 2, 5)) == "1:2:5"
Expand Down
6 changes: 3 additions & 3 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function test_typed_ast_printing(Base.@nospecialize(f), Base.@nospecialize(types
must_used_checked[sym] = false
end
for str in (sprint(code_warntype, f, types),
stringmime("text/plain", src))
repr("text/plain", src))
for var in must_used_vars
@test contains(str, string(var))
end
Expand Down Expand Up @@ -381,8 +381,8 @@ test_typed_ast_printing(g15714, Tuple{Vector{Float32}},
let li = typeof(fieldtype).name.mt.cache.func::Core.MethodInstance,
lrepr = string(li),
mrepr = string(li.def),
lmime = stringmime("text/plain", li),
mmime = stringmime("text/plain", li.def)
lmime = repr("text/plain", li),
mmime = repr("text/plain", li.def)

@test lrepr == lmime == "MethodInstance for fieldtype(...)"
@test mrepr == mmime == "fieldtype(...) in Core"
Expand Down
6 changes: 3 additions & 3 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ test_repr("a.:(begin
@test repr(Tuple{Float32, Float32, Float32}) == "Tuple{Float32,Float32,Float32}"

# Test that REPL/mime display of invalid UTF-8 data doesn't throw an exception:
@test isa(stringmime("text/plain", String(UInt8[0x00:0xff;])), String)
@test isa(repr("text/plain", String(UInt8[0x00:0xff;])), String)

# don't use julia-specific `f` in Float32 printing (PR #18053)
@test sprint(print, 1f-7) == "1.0e-7"
Expand Down Expand Up @@ -1036,10 +1036,10 @@ end
anonfn_type_repr = "getfield($modname, Symbol(\"$(typeof(anonfn).name.name)\"))"
@test repr(typeof(anonfn)) == anonfn_type_repr
@test repr(anonfn) == anonfn_type_repr * "()"
@test stringmime("text/plain", anonfn) == "$(typeof(anonfn).name.mt.name) (generic function with 1 method)"
@test repr("text/plain", anonfn) == "$(typeof(anonfn).name.mt.name) (generic function with 1 method)"
mkclosure = x->y->x+y
clo = mkclosure(10)
@test stringmime("text/plain", clo) == "$(typeof(clo).name.mt.name) (generic function with 1 method)"
@test repr("text/plain", clo) == "$(typeof(clo).name.mt.name) (generic function with 1 method)"
@test repr(UnionAll) == "UnionAll"
end

Expand Down