Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed May 5, 2024
1 parent 0f31a8c commit 8ecac26
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/style_helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# trbl() constructs correct data

`top` must be a number or `NULL`, not the string "a".

---

`right` must be a number or `NULL`, not the string "a".

---

`bottom` must be a number, not the string "a".

---

`left` must be a number or `NULL`, not the string "a".

4 changes: 3 additions & 1 deletion tests/testthat/test-style.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ test_that("style checks it's inputs", {
expect_snapshot_error(style(background = TRUE))
expect_silent(s <- style(background = NA))
expect_type(s$background, "character")
expect_silent(s <- style(background = linearGradient()))
if ("linearGradient" %in% getNamespaceExports("grid")) {
expect_silent(s <- style(background = linearGradient()))
}

# Border
expect_silent(s <- style(border = "red"))
Expand Down
62 changes: 62 additions & 0 deletions tests/testthat/test-style_helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
test_that("modifiers are constructed correctly", {
x <- relative(1)
expect_s3_class(x, "marquee_relative")
expect_true(is_relative(x))
expect_true(is_modifier(x))
expect_type(x, "list")
expect_equal(x[[1]], 1)

x <- em(1)
expect_s3_class(x, "marquee_em")
expect_true(is_em(x))
expect_true(is_modifier(x))
expect_type(x, "list")
expect_equal(x[[1]], 1)

x <- rem(1)
expect_s3_class(x, "marquee_rem")
expect_true(is_rem(x))
expect_true(is_modifier(x))
expect_type(x, "list")
expect_equal(x[[1]], 1)
})

test_that("trbl() constructs correct data", {
expect_equal(trbl(1), trbl(1, 1, 1, 1))
expect_equal(trbl(1, 2), trbl(1, 2, 1, 2))
expect_equal(trbl(1, 2, 3), trbl(1, 2, 3, 2))

expect_snapshot_error(trbl("a", 1, 1, 1))
expect_snapshot_error(trbl(1, "a", 1, 1))
expect_snapshot_error(trbl(1, 1, "a", 1))
expect_snapshot_error(trbl(1, 1, 1, "a"))

expect_silent(trbl(relative(1), 1, 1, 1))
expect_silent(trbl(1, em(1), 1, 1))
expect_silent(trbl(1, 1, rem(1), 1))

box <- trbl(1, relative(1), em(1), rem(1))
expect_s3_class(box, "marquee_trbl")
expect_true(is_trbl(box))
expect_equal(box[[1]], 1)
expect_equal(box[[2]], relative(1))
expect_equal(box[[3]], em(1))
expect_equal(box[[4]], rem(1))
})

test_that("skip_inherit() works with different types", {
expect_s3_class(skip_inherit(1), "marquee_skip_inherit")
expect_s3_class(skip_inherit(relative(1)), "marquee_skip_inherit")
expect_s3_class(skip_inherit(em(1)), "marquee_skip_inherit")
expect_s3_class(skip_inherit(rem(1)), "marquee_skip_inherit")

expect_s3_class(skip_inherit(relative(1)), "marquee_relative")
expect_s3_class(skip_inherit(em(1)), "marquee_em")
expect_s3_class(skip_inherit(rem(1)), "marquee_rem")

box <- skip_inherit(trbl(1, 2, 3, 4))
expect_s3_class(box[[1]], "marquee_skip_inherit")
expect_s3_class(box[[2]], "marquee_skip_inherit")
expect_s3_class(box[[3]], "marquee_skip_inherit")
expect_s3_class(box[[4]], "marquee_skip_inherit")
})

0 comments on commit 8ecac26

Please sign in to comment.