From f05dd3d26976ae8310cfb512cf0106505e95b51b Mon Sep 17 00:00:00 2001 From: rened Date: Thu, 29 Mar 2018 19:22:19 +0200 Subject: [PATCH] fixes for 0.7 (#249) * fixes for 0.7 * fixes for 0.7 --- src/JSON.jl | 2 ++ src/Writer.jl | 4 ++-- src/bytes.jl | 8 ++++++-- src/specialized.jl | 2 +- test/async.jl | 4 ++++ test/runtests.jl | 3 +-- test/serializer.jl | 2 +- test/standard-serializer.jl | 4 ++-- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/JSON.jl b/src/JSON.jl index 4e5a01e..b5f9e5b 100644 --- a/src/JSON.jl +++ b/src/JSON.jl @@ -2,6 +2,8 @@ __precompile__() module JSON +using Compat + export json # returns a compact (or indented) JSON representation as a string export JSONText # string wrapper to insert raw JSON into JSON output diff --git a/src/Writer.jl b/src/Writer.jl index 054d259..7335f5b 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -359,8 +359,8 @@ print(io::IO, obj, indent) = show_json(io, StandardSerialization(), obj; indent=indent) print(io::IO, obj) = show_json(io, StandardSerialization(), obj) -print(a, indent) = print(STDOUT, a, indent) -print(a) = print(STDOUT, a) +print(a, indent) = print(stdout, a, indent) +print(a) = print(stdout, a) json(a) = sprint(print, a) json(a, indent) = sprint(print, a, indent) diff --git a/src/bytes.jl b/src/bytes.jl index 048c6da..a5f2768 100644 --- a/src/bytes.jl +++ b/src/bytes.jl @@ -44,7 +44,7 @@ const ESCAPES = Dict( LATIN_T => TAB) const REVERSE_ESCAPES = Dict(reverse(p) for p in ESCAPES) -const ESCAPED_ARRAY = Vector{Vector{UInt8}}(uninitialized, 256) +const ESCAPED_ARRAY = Vector{Vector{UInt8}}(undef, 256) for c in 0x00:0xFF ESCAPED_ARRAY[c + 1] = if c == SOLIDUS [SOLIDUS] # don't escape this one @@ -53,7 +53,11 @@ for c in 0x00:0xFF elseif haskey(REVERSE_ESCAPES, c) [BACKSLASH, REVERSE_ESCAPES[c]] elseif iscntrl(Char(c)) || !isprint(Char(c)) - UInt8[BACKSLASH, LATIN_U, hex(c, 4)...] + if VERSION < v"0.7.0-DEV.4446" + UInt8[BACKSLASH, LATIN_U, hex(c, 4)...] + else + UInt8[BACKSLASH, LATIN_U, string(c, base=16, pad=4)...] + end else [c] end diff --git a/src/specialized.jl b/src/specialized.jl index ff885da..f796e4e 100644 --- a/src/specialized.jl +++ b/src/specialized.jl @@ -62,7 +62,7 @@ function predict_string(ps::MemoryParserState) if ps[s] == LATIN_U # Unicode escape t = ps.s ps.s = s + 1 - len += write(DevNull, read_unicode_escape!(ps)) + len += write(devnull, read_unicode_escape!(ps)) s = ps.s ps.s = t continue diff --git a/test/async.jl b/test/async.jl index 74831c8..6ef44e7 100644 --- a/test/async.jl +++ b/test/async.jl @@ -1,5 +1,9 @@ finished_async_tests = RemoteChannel() +if VERSION >= v"0.7.0-DEV.4442" + using Sockets +end + @async begin s = listen(7777) s = accept(s) diff --git a/test/runtests.jl b/test/runtests.jl index c11c1cd..fb4d1a1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,5 +78,4 @@ end end end -# Check that printing to the default STDOUT doesn't fail -JSON.print(["JSON.jl tests pass!"], 1) +# Check that printing to the default stdout doesn't fail diff --git a/test/serializer.jl b/test/serializer.jl index 5f8aa3e..24b0b2e 100644 --- a/test/serializer.jl +++ b/test/serializer.jl @@ -74,7 +74,7 @@ end struct SingletonType end @test_throws ErrorException json(SingletonType()) -# test printing to STDOUT +# test printing to stdout let filename = tempname() open(filename, "w") do f redirect_stdout(f) do diff --git a/test/standard-serializer.jl b/test/standard-serializer.jl index 3f1bd2b..07e37ab 100644 --- a/test/standard-serializer.jl +++ b/test/standard-serializer.jl @@ -46,8 +46,8 @@ end @testset "Null bytes" begin zeros = Dict("\0" => "\0") json_zeros = json(zeros) - @test contains(json_zeros,"\\u0000") - @test !contains(json_zeros,"\\0") + @test occursin("\\u0000", json_zeros) + @test !occursin("\\0", json_zeros) @test JSON.parse(json_zeros) == zeros end