Skip to content

Commit

Permalink
Fix tuple reading issue in a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Oct 27, 2019
1 parent de7e115 commit bc73d23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ end
@wh
if N == i
if b == UInt8(']')
return pos, Base.@ncall i tuple x
return pos + 1, Base.@ncall i tuple x
else
error = ExpectedClosingArrayChar
@goto invalid
Expand Down Expand Up @@ -842,6 +842,7 @@ end
pos += 1
return pos, y
elseif b != UInt8(',')
@show pos, y, Char(b)
error = ExpectedComma
@goto invalid
end
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Test, JSON3, UUIDs

struct data
t :: Tuple{Symbol, String}
end

@enum Fruit apple banana

struct XInt
Expand Down Expand Up @@ -636,4 +640,7 @@ obj = JSON3.read("{\"a\":\"b\", \"b\":null, \"c\":[null,null]}")
@test JSON3.read("[\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\",\"hey\"]", NTuple{35, String}) ==
("hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey", "hey")

JSON3.StructType(::Type{data}) = JSON3.Struct()
@test JSON3.read("{\"t\":[\"car\",\"Mercedes\"]}", data) == data((:car, "Mercedes"))

end # @testset "JSON3"

0 comments on commit bc73d23

Please sign in to comment.