Skip to content

Commit

Permalink
fmtr
Browse files Browse the repository at this point in the history
  • Loading branch information
vdayanand committed Jul 4, 2024
1 parent 92dce9c commit 97bb409
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions test/param_serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,92 @@ using OpenAPI.Servers: deserialize_deep_object
using OpenAPI: convert_dicts_to_arrays
@testset "Test deserialize_deep_object" begin
@testset "Single level object" begin
query_string = Dict("key1"=>"value1", "key2"=>"value2")
query_string = Dict("key1" => "value1", "key2" => "value2")
expected = Dict("key1" => "value1", "key2" => "value2")
@test deserialize_deep_object(query_string) == expected
end

@testset "Nested object" begin
query_string = Dict("outer[inner]"=>"value")
query_string = Dict("outer[inner]" => "value")
expected = Dict("outer" => Dict("inner" => "value"))
@test deserialize_deep_object(query_string) == expected
end
@testset "Deeply nested object" begin
query_string = Dict("a[b][c][d]"=>"value")
query_string = Dict("a[b][c][d]" => "value")
expected = Dict("a" => Dict("b" => Dict("c" => Dict("d" => "value"))))
@test deserialize_deep_object(query_string) == expected
end

@testset "Multiple nested objects" begin
query_string = Dict("a[b]"=>"value1", "a[c]"=>"value2")
query_string = Dict("a[b]" => "value1", "a[c]" => "value2")
expected = Dict("a" => Dict("b" => "value1", "c" => "value2"))
@test deserialize_deep_object(query_string) == expected
end

@testset "List of values" begin
query_string = Dict("a[0]"=>"value1", "a[1]"=>"value2")
expected = Dict("a"=>Dict("0"=>"value1", "1"=>"value2"))
query_string = Dict("a[0]" => "value1", "a[1]" => "value2")
expected = Dict("a" => Dict("0" => "value1", "1" => "value2"))
@test deserialize_deep_object(query_string) == expected
end

@testset "Mixed structure" begin
query_string = Dict("a[b]"=>"value1", "a[c][0]"=>"value2", "a[c][1]"=>"value3")
expected = Dict("a" => Dict("b" => "value1", "c" => Dict("0"=>"value2", "1"=>"value3")))
query_string =
Dict("a[b]" => "value1", "a[c][0]" => "value2", "a[c][1]" => "value3")
expected = Dict(
"a" => Dict("b" => "value1", "c" => Dict("0" => "value2", "1" => "value3")),
)
@test deserialize_deep_object(query_string) == expected
end

@testset "convert_dicts_to_arrays" begin
example = Dict("a" => Dict("b" => "value1", "c" => Dict("0"=>"value2", "1"=>"value3")))
example = Dict(
"a" => Dict("b" => "value1", "c" => Dict("0" => "value2", "1" => "value3")),
)
@test convert_dicts_to_arrays(example) == example
@test convert_dicts_to_arrays(example["a"]["c"]) == ["value2", "value3"]
end

@testset "Blank values" begin
query_string = Dict("a[b]"=>"", "a[c]"=>"")
query_string = Dict("a[b]" => "", "a[c]" => "")
expected = Dict("a" => Dict("b" => "", "c" => ""))
@test deserialize_deep_object(query_string) == expected
end

@testset "Complex nested structure" begin
query_string = Dict("a[b][c][d]"=>"value1", "a[b][c][e]"=>"value2", "a[f]"=>"value3")
expected = Dict("a" => Dict("b" => Dict("c" => Dict("d" => "value1", "e" => "value2")), "f" => "value3"))
query_string =
Dict("a[b][c][d]" => "value1", "a[b][c][e]" => "value2", "a[f]" => "value3")
expected = Dict(
"a" => Dict(
"b" => Dict("c" => Dict("d" => "value1", "e" => "value2")),
"f" => "value3",
),
)
@test deserialize_deep_object(query_string) == expected
end
@testset "Complex nested structure with numbers and nessted" begin
query_string = Dict{String, String}(
"filter[0][name]" => "name",
"filter[0][data][0]" => "Dog",
"pagination[type]" => "offset",
"pagination[page]" => "1",
"filter[0][type]" => "FilterSet",
"pagination[per_page]" => "5", "pagination[foo]" => "5.0")
query_string = Dict{String,String}(
"filter[0][name]" => "name",
"filter[0][data][0]" => "Dog",
"pagination[type]" => "offset",
"pagination[page]" => "1",
"filter[0][type]" => "FilterSet",
"pagination[per_page]" => "5",
"pagination[foo]" => "5.0",
)
expected = Dict(
"pagination" => Dict( "page" => "1",
"per_page" => "5",
"type" => "offset", "foo"=>"5.0"),
"filter"=>Dict("0"=>Dict(
"name" => "name", "data" => Dict("0"=>"Dog"), "type" => "FilterSet"))
"pagination" => Dict(
"page" => "1",
"per_page" => "5",
"type" => "offset",
"foo" => "5.0",
),
"filter" => Dict(
"0" => Dict(
"name" => "name",
"data" => Dict("0" => "Dog"),
"type" => "FilterSet",
),
),
)
d = deserialize_deep_object(query_string)
@test d["pagination"] == expected["pagination"]
Expand Down

0 comments on commit 97bb409

Please sign in to comment.