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

Improve show for nested Objects #301

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/JSON3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ end

Object() = Object(codeunits(""), UInt64[object(Int64(2)), 0], Dict{Symbol, Int}())

# show(::IO, ::MIME"text/plain", ::AbstractDict) gets used at the top level
# This method below is used for nested objects
Base.show(io::IO, obj::Object) = JSON3.write(io, obj)

"""An immutable (read only) struct which provides an efficient view of a JSON array. Supports the `AbstractArray` interface. See [built in types](#Builtin-types) for more detail on why we have an `Array` type."""
struct Array{T, S <: AbstractVector{UInt8}, TT <: AbstractVector{UInt64}} <: AbstractVector{T}
buf::S
Expand Down Expand Up @@ -167,7 +171,6 @@ Base.copy(arr::Array) = map(x->x isa Object || x isa Array ? copy(x) : x, arr)

include("read.jl")
include("strings.jl")
include("show.jl")
include("structs.jl")
include("write.jl")
include("pretty.jl")
Expand Down
51 changes: 0 additions & 51 deletions src/show.jl

This file was deleted.

12 changes: 5 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,14 @@ json = JSON3.write(w)

end # @testset "structs.jl"

@testset "show.jl" begin
@testset "repr" begin

@test repr(JSON3.read("{}")) == "{}"
@test repr(JSON3.read("{\"a\": 1}")) == "{\n \"a\": 1\n}"
@test repr(JSON3.read("{\"a\": {\"b\": 2}}")) == "{\n \"a\": {\n \"b\": 2\n }\n}"
# @test repr(JSON3.read("[]")) == "[]"
# @test repr(JSON3.read("[1,2,3]")) == "[\n 1,\n 2,\n 3\n]"
# @test repr(JSON3.read("[1,[2.1,2.2,2.3],3]")) == "[\n 1,\n [\n 2.1,\n 2.2,\n 2.3\n ],\n 3\n]"
@test repr(JSON3.read("{\"a\": 1}")) == "{\"a\":1}"
@test repr(JSON3.read("{\"a\": {\"b\": 2}}")) == "{\"a\":{\"b\":2}}"
@test repr(JSON3.read("[1,2,3]")) == "[1, 2, 3]"

end # @testset "show.jl"
end # @testset "repr"

include("json.jl")

Expand Down