@@ -3,8 +3,10 @@ using BenchmarkTools
3
3
using StableRNGs
4
4
using Test
5
5
6
- import RecipesPipeline: _prepare_series_data
6
+ import Dates
7
+ import RecipesPipeline: _prepare_series_data, _apply_type_recipe
7
8
import RecipesBase
9
+ import RecipesBase: @recipe
8
10
9
11
@testset " DefaultsDict" begin
10
12
dd = DefaultsDict (Dict (:foo => 1 , :bar => missing ), Dict (:foo => nothing , :baz => ' x' ))
82
84
@test RecipesBase. is_key_supported (" key" )
83
85
end
84
86
87
+ @testset " _apply_type_recipe" begin
88
+ plt = nothing
89
+ plotattributes = Dict {Symbol,Any} (:plot_object => plt)
90
+ @test _apply_type_recipe (plotattributes, [1 , 2 , 3 ], :x ) == [1 , 2 , 3 ]
91
+ @test _apply_type_recipe (plotattributes, [[1 , 2 ], [3 , 4 ]], :x ) == [[1 , 2 ], [3 , 4 ]]
92
+ res = _apply_type_recipe (plotattributes, [Dates. Date (2001 )], :x )
93
+ @test typeof (res) <: Formatted
94
+ @test res. data == [Dates. value (Dates. Date (2001 ))]
95
+ @test res. formatter (Dates. value (Dates. Date (2001 ))) == " 2001-01-01"
96
+
97
+ res = _apply_type_recipe (plotattributes, [[Dates. Date (2001 )]], :x )
98
+ @test typeof (res) <: Formatted
99
+ @test res. data == [[Dates. value (Dates. Date (2001 ))]]
100
+ @test res. formatter (Dates. value (Dates. Date (2001 ))) == " 2001-01-01"
101
+
102
+ struct Test1 <: Number
103
+ val:: Float64
104
+ end
105
+
106
+ @recipe f (:: Type{T} , v:: T ) where {T<: AbstractVector{<:Test1} } = map (x -> x. val + 1 , v)
107
+
108
+ @test _apply_type_recipe (plotattributes, Test1 .([1 , 2 , 3 ]), :x ) == [2.0 , 3.0 , 4.0 ]
109
+ @test _apply_type_recipe (plotattributes, [Test1 .([1 , 2 , 3 ])], :x ) == [[2.0 , 3.0 , 4.0 ]]
110
+
111
+ struct Test2 <: Number
112
+ val:: Float64
113
+ end
114
+
115
+ @recipe f (:: Type{T} , v:: T ) where {T<: AbstractVector{<:AbstractVector{<:Test2}} } =
116
+ map (x -> map (y -> y. val + 2 , x), v)
117
+
118
+ @test _apply_type_recipe (plotattributes, Test2 .([1 , 2 , 3 ]), :x ) == Test2 .([1 , 2 , 3 ])
119
+ @test _apply_type_recipe (plotattributes, [Test2 .([1 , 2 , 3 ])], :x ) == [[3.0 , 4.0 , 5.0 ]]
120
+ end
121
+
85
122
@testset " _prepare_series_data" begin
86
123
@test_throws ErrorException _prepare_series_data (:test )
87
124
@test _prepare_series_data (nothing ) ≡ nothing
0 commit comments