| 1 |
# Disable sass cache |
| 2 |
local_disable_cache() |
| 3 |
|
| 4 |
test_that("unnamed options fail", { |
| 5 |
sass_options <- sass_options() |
| 6 |
names(sass_options) <- NULL |
| 7 |
expect_error( |
| 8 |
sass("foo { margin: 122px * .3; }", options = sass_options), |
| 9 |
"No named options" |
| 10 |
) |
| 11 |
}) |
| 12 |
|
| 13 |
test_that("too few options fail", { |
| 14 |
sass_options <- sass_options() |
| 15 |
sass_options$precision <- NULL |
| 16 |
expect_error( |
| 17 |
sass("foo { margin: 122px * .3; }", options = sass_options), |
| 18 |
"missing" |
| 19 |
) |
| 20 |
}) |
| 21 |
|
| 22 |
test_that("too many options fail", { |
| 23 |
sass_options <- sass_options() |
| 24 |
sass_options$new <- "hello" |
| 25 |
expect_error( |
| 26 |
sass("foo { margin: 122px * .3; }", options = sass_options), |
| 27 |
"unsupported" |
| 28 |
) |
| 29 |
}) |
| 30 |
|
| 31 |
test_that("wrong options fail", { |
| 32 |
sass_options <- sass_options() |
| 33 |
sass_options$precision <- NULL |
| 34 |
sass_options$blah <- "hello" |
| 35 |
expect_error( |
| 36 |
sass("foo { margin: 122px * .3; }", options = sass_options), |
| 37 |
"precision" |
| 38 |
) |
| 39 |
}) |
| 40 |
|
| 41 |
test_that("wrong type fails", { |
| 42 |
sass_options <- sass_options() |
| 43 |
sass_options$precision <- "hello" |
| 44 |
expect_error( |
| 45 |
sass("foo { margin: 122px * .3; }", options = sass_options), |
| 46 |
"Invalid type for precision" |
| 47 |
) |
| 48 |
}) |
| 49 |
|
| 50 |
test_that("Global options work", { |
| 51 |
on.exit(sass_options_set(NULL), add = TRUE) |
| 52 |
|
| 53 |
expect_identical(sass_options_get(), sass_options()) |
| 54 |
|
| 55 |
old_options <- sass_options_set(precision = 10) |
| 56 |
expect_equal( |
| 57 |
sass_options_get(), |
| 58 |
sass_options(precision = 10), |
| 59 |
ignore_attr = TRUE |
| 60 |
) |
| 61 |
|
| 62 |
expect_equal( |
| 63 |
sass_options_get(precision = 11), |
| 64 |
sass_options(precision = 11), |
| 65 |
ignore_attr = TRUE |
| 66 |
) |
| 67 |
|
| 68 |
sass_options_set(old_options) |
| 69 |
expect_identical(sass_options_get(), sass_options()) |
| 70 |
|
| 71 |
sass_options_set(precision = 12) |
| 72 |
opts <- sass_options_get() |
| 73 |
sass_options_set(precision = 13) |
| 74 |
sass_options_set(opts) |
| 75 |
expect_equal( |
| 76 |
sass_options_get(), |
| 77 |
sass_options(precision = 12), |
| 78 |
ignore_attr = TRUE |
| 79 |
) |
| 80 |
|
| 81 |
expect_error( |
| 82 |
sass_options_set(1), |
| 83 |
"sass_options" |
| 84 |
) |
| 85 |
expect_error( |
| 86 |
sass_options_get(foo = "bar"), |
| 87 |
"foo" |
| 88 |
) |
| 89 |
}) |
| 90 |
|
| 91 |
test_that("Global options work 2", { |
| 92 |
expect_identical(sass_options_get(), sass_options()) |
| 93 |
}) |