diff --git a/test/Charts.jl b/test/Charts.jl index 4f95e6e..fc503ed 100644 --- a/test/Charts.jl +++ b/test/Charts.jl @@ -34,23 +34,4 @@ end @test pd[2].text[2] == "D" end end -end - -@testset "JSONText from PlotlyBase extension" begin - - using Stipple - @testset "Stipple.JSONText" begin - @test ! @isdefined PBPlotWithEvents - using PlotlyBase, PlotlyBase.JSON - @test @isdefined PBPlotWithEvents - - sc = scatter(x = StipplePlotly.JSONText("jsontext"), more_of_this = "a") - pl = Plot(sc) - @test JSON.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}" - @test contains(JSON.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}") - - @test Stipple.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}" - @test contains(Stipple.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}") - end - end \ No newline at end of file diff --git a/test/PlotlyBaseExtension.jl b/test/PlotlyBaseExtension.jl new file mode 100644 index 0000000..57ae87f --- /dev/null +++ b/test/PlotlyBaseExtension.jl @@ -0,0 +1,66 @@ +@testset "PlotlyBase extension" begin + + using Stipple + @testset "Stipple.JSONText" begin + @test ! @isdefined(PBPlotWithEvents) || @isdefined(PlotlyBase) + using PlotlyBase, PlotlyBase.JSON + @test @isdefined PBPlotWithEvents + + sc = scatter(x = StipplePlotly.JSONText("jsontext"), more_of_this = "a") + pl = Plot(sc) + @test JSON.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}" + @test contains(JSON.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}") + + @test Stipple.json(sc) == "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}" + @test contains(Stipple.json(pl), "{\"type\":\"scatter\",\"more\":{\"of\":{\"this\":\"a\"}},\"x\":jsontext}") + end + + @testset "Parsing" begin + using Stipple + import Stipple.stipple_parse + + @testset "Layout" begin + pl = PlotlyBase.Layout(xaxis_range = [1, 2]) + pl_d = JSON3.read(Stipple.json(render(pl)), Dict) + + pl_in = stipple_parse(PlotlyBase.Layout, pl_d) + @test pl_in[:xaxis_range] == [1, 2] + + pl_in = stipple_parse(PlotlyBase.Layout{Dict{Symbol, Any}}, pl_d) + pl_in[:xaxis_range] == [1, 2] + + if VersionNumber(Genie.Assets.package_version(Stipple)) >= v"0.30.5" + pl_in = stipple_parse(PlotlyBase.Layout{OrderedDict{Symbol, Any}}, pl_d) + @test pl_in[:xaxis_range] == [1, 2] + end + end + + @testset "GenericTrace" begin + tr = scatter(x = [1, 2, 3], y = [3, 4, 5]) + tr_d = JSON3.read(Stipple.json(render(tr)), Dict) + + tr_in = stipple_parse(GenericTrace, tr_d) + @test tr_in.x == [1, 2, 3] + @test tr_in.y == [3, 4, 5] + end + + @testset "Plot" begin + pl = PlotlyBase.Plot([scatter(x = [1, 2, 3], y = [3, 4, 5])], PlotlyBase.Layout(xaxis_range = [1, 2])) + pl_d = JSON3.read(Stipple.json(render(pl)), Dict) + + pl_in = stipple_parse(PlotlyBase.Plot, pl_d) + @test length(pl_in.data) == 1 + @test pl_in.layout[:xaxis_range] == [1, 2] + + T = Plot() |> typeof + T = Plot + pl_in = stipple_parse(T, pl_d) + @test length(pl_in.data) == 1 + @test pl_in.data[1][:x] == [1, 2, 3] + @test pl_in.layout[:xaxis_range] == [1, 2] + end + end + +end + +pl = PlotlyBase.Layout(xaxis_range = [1, 2]) \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 37fdd9b..f0691dd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,8 +2,13 @@ using StipplePlotly using Test using DataFrames -@testset verbose = true "Charts" begin +files = filter(endswith(".jl"), readdir(@__DIR__)) - include("Charts.jl") +for file in files + file == "runtests.jl" && continue + title = file[1:end-3] + @testset verbose = true "$title" begin + include(file) + end end