Skip to content

Commit

Permalink
Add tests for parsing NaN, Infinity, and -Infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
kmsquire committed May 16, 2019
1 parent ff02446 commit 306bf8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/parser/nan-inf.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@testset begin
test_str = """{"x": NaN, "y": Infinity, "z": -Infinity}"""
@test_throws ErrorException JSON.parse(test_str)
val = JSON.parse(test_str, allownan=true)
@test val["x"] === NaN
@test val["y"] == Inf
@test val["z"] == -Inf

@test_throws ErrorException JSON.parse(IOBuffer(test_str))
val2 = JSON.parse(IOBuffer(test_str), allownan=true)
@test val2["x"] === NaN
@test val2["y"] == Inf
@test val2["z"] == -Inf
end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ include("json-samples.jl")
include("parser/inttype.jl")
end

@testset "nan_inf" begin
include("parser/nan-inf.jl")
end

@testset "Miscellaneous" begin
# test for single values
@test JSON.parse("true") == true
Expand Down

0 comments on commit 306bf8a

Please sign in to comment.