@@ -121,14 +121,60 @@ test_that("color_scheme_view returns gtable if length(scheme) >= 1", {
121
121
122
122
123
123
124
- # ggplot theme ------------------------------------------------------------
124
+ # ggplot themes ------------------------------------------------------------
125
+
126
+ default <- theme_default()
127
+ minimal <- ggplot2 :: theme_minimal()
128
+ dark <- ggplot2 :: theme_dark()
129
+
125
130
test_that(" theme_default creates ggplot theme" , {
126
- thm1 <- theme_default()
127
- expect_type(thm1 , " list" )
128
- expect_s3_class(thm1 , " theme" )
131
+ expect_type(default , " list" )
132
+ expect_s3_class(default , " theme" )
129
133
130
134
thm2 <- theme_default(base_size = 13 )
131
135
expect_type(thm2 , " list" )
132
136
expect_s3_class(thm2 , " theme" )
133
137
expect_equal(thm2 [[" text" ]][[" size" ]], 13 )
134
138
})
139
+
140
+ test_that(" bayesplot_theme_set/get work" , {
141
+ bayesplot_theme_set()
142
+ expect_identical(bayesplot_theme_get(), default )
143
+ expect_identical(bayesplot_theme_set(), default )
144
+
145
+ old <- bayesplot_theme_set(minimal )
146
+ expect_identical(old , default )
147
+ expect_identical(bayesplot_theme_get(), minimal )
148
+ })
149
+
150
+ test_that(" bayesplot_theme_update/replace work" , {
151
+ bayesplot_theme_set(minimal )
152
+ old <- bayesplot_theme_update(axis.text.x = ggplot2 :: element_text(color = " red" ))
153
+ expect_identical(old , minimal )
154
+
155
+ thm <- bayesplot_theme_get()
156
+ expect_identical(thm , minimal + xaxis_text(color = " red" ))
157
+ expect_equal(thm $ axis.text.x $ colour , " red" )
158
+ expect_null(thm $ axis.text.x $ size )
159
+
160
+ bayesplot_theme_update(axis.text.x = ggplot2 :: element_text(size = 13 ))
161
+ thm <- bayesplot_theme_get()
162
+ expect_equal(thm $ axis.text.x $ colour , " red" )
163
+ expect_equal(thm $ axis.text.x $ size , 13 )
164
+
165
+ old <- bayesplot_theme_replace(axis.text.x = ggplot2 :: element_text(color = " green" ))
166
+ expect_identical(old , thm )
167
+ thm <- bayesplot_theme_get()
168
+ expect_equal(thm $ axis.text.x $ colour , " green" )
169
+ expect_null(thm $ axis.text.x $ size )
170
+ })
171
+
172
+ test_that(" ggplot2::theme_set overrides bayesplot theme" , {
173
+ ggplot2 :: theme_set(dark )
174
+ bayesplot_theme_set()
175
+ expect_identical(ggplot2 :: theme_get(), dark )
176
+ expect_identical(bayesplot_theme_get(), default )
177
+
178
+ ggplot2 :: theme_set(minimal )
179
+ expect_identical(bayesplot_theme_get(), minimal )
180
+ })
0 commit comments