Mercurial > lbo > hg > juliaplay
view julia/JSONStructs/test/runtests.jl @ 40:5e3662b65004 default tip
Land/water find peak problem
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 03 Apr 2023 22:04:42 +0200 |
parents | 8a21e7a32029 |
children |
line wrap: on
line source
# Some basic tests. using JSONStructs @json_parseable struct TestStruct1 a::Int b::Float64 c::Vector{String} end function test_parse_1() json = "{\"a\": 33, \"b\": 55.55, \"c\": [\"xyz\", \"abc\"]}" have = parse_struct(TestStruct1, json) want = TestStruct1(33, 55.55, ["xyz", "abc"]) @show have, want @assert string(have) == string(want) "$have == $want" end @json_parseable struct OuterStruct a::String b::TestStruct1 end function test_parse_2() json = "{\"a\": \"Outer Struct\", \"b\": {\"a\": 33, \"b\": 55.55, \"c\": [\"xyz\", \"abc\"]}}" have = parse_struct(OuterStruct, json) want = OuterStruct("Outer Struct", TestStruct1(33, 55.55, ["xyz", "abd"])) @show have, want @assert string(have) == string(want) "$have == $want" end println("Starting JSONStructs test") test_parse_1() test_parse_2()