1test_that("global theme api works", {
2  bs_global_theme(version = 4, bootswatch = "sketchy")
3  on.exit(bs_global_clear(), add = TRUE)
4
5  # Can retrieve theme version/bootswatch
6  sketchy_theme <- bs_global_get()
7  expect_equal(theme_version(sketchy_theme), "4")
8  expect_equal(theme_bootswatch(sketchy_theme), "sketchy")
9
10  # Setting a new theme overrides the old one
11  bs_global_theme(version = 4, bootswatch = "cosmo")
12  cosmo_theme <- bs_global_get()
13  expect_equal(theme_version(cosmo_theme), "4")
14  expect_equal(theme_bootswatch(cosmo_theme), "cosmo")
15
16  # Can add new variable defaults
17  bs_global_add_variables("primary" = "red !default;")
18  primary <- sass_partial("body{background:$primary;}", bs_global_get())
19  expect_css("body{background:red;}", primary)
20
21  # Can clear
22  bs_global_clear()
23  expect_null(bs_global_get())
24
25  # Adding without a set errors
26  expect_error(bs_global_bundle())
27
28  # Can set a theme object as the current theme
29  bs_global_set(cosmo_theme)
30  primary <- sass_partial("body{background:$primary;}", bs_global_get())
31  expect_css("body{background:#2780e3;}", primary)
32})
33
34
35test_that("Theme adding works as intended", {
36  bs_global_theme()
37  on.exit(bs_global_clear(), add = TRUE)
38  # Can override variable defaults
39  bs_global_add_variables(primary = "blue !default;")
40  bs_global_add_variables(primary = "#fff !default;")
41  css <- sass_partial(".foo{color:$primary;}", bs_global_get())
42  expect_css(".foo{color:#fff;}", css)
43
44  # Also works without default flags and can handle numeric values
45  bs_global_add_variables(primary = "blue")
46  bs_global_add_variables(primary = "#fff", "font-size" = 0)
47  css <- sass_partial(".foo{color:$primary;font-size:0}", bs_global_get())
48  expect_css(".foo{color:#fff;font-size:0;}", css)
49
50  # Can also override variables via declarations
51  bs_global_add_variables(
52    .where = "mixins",
53    "primary" = "$secondary",
54    "body-color" = "color-contrast($primary)"
55  )
56  css <- sass_partial(".foo{color:$primary;}", bs_global_get())
57  expect_css(".foo{color:#6c757d;}", css)
58})
59
60
61test_that("rename works as intended", {
62  expect_identical(
63    rename2(list(a=1, b=3, c=4, a=2), b="z", f="w", a="y"),
64    list(y = 1, z = 3, c = 4, y = 2)
65  )
66  expect_identical(
67    rename2(c("a", "b", "c", "a"), b="z", f="w", a="y"),
68    c("y", "z", "c", "y")
69  )
70})
71