Skip to content

Commit e2f3931

Browse files
more thorough transformer testing
1 parent c430adc commit e2f3931

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

R/style-guides.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ tidyverse_style <- function(scope = "tokens",
178178
# remove_space_before_closing_paren = c("')'", "']'"),
179179
# remove_space_before_opening_paren = c("'('", "'['", "LBB"),
180180
add_space_after_for_if_while = c("IF", "WHILE", "FOR"),
181-
add_space_before_brace = "'{'",
181+
# remove_space_before_comma = "','",
182182
set_space_between_eq_sub_and_comma = "EQ_SUB",
183183
style_space_around_math_token = c(
184184
math_token_spacing$zero,
@@ -222,7 +222,7 @@ tidyverse_style <- function(scope = "tokens",
222222
)
223223
)
224224

225-
if (getRversion() >= 3.6) {
225+
if (getRversion() < 3.6) {
226226
transformers_drop$token$force_assignment_op <- NULL
227227
}
228228

tests/testthat/test-transformers-drop.R

+55
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,61 @@ test_that("transformers are removed if they are unused", {
4545
expect_equal(t_fun, t_manual)
4646
})
4747

48+
test_that("tidyverse transformers are correctly dropped", {
49+
t_style <- tidyverse_style()
50+
51+
t_fun <- transformers_drop(
52+
"x", t_style
53+
)
54+
# test that all dropping rules match an actual rule in the style guide
55+
scopes <- intersect(
56+
names(t_fun$transformers_drop),
57+
names(t_fun)
58+
)
59+
purrr::map2(t_fun$transformers_drop, t_style[scopes], function(x, y) {
60+
# all x must be in y. select the x that are not in y
61+
diff <- setdiff(names(x),names(y))
62+
if (length(diff) > 0) {
63+
rlang::abort(paste(
64+
"transformer_dropping specifies exclusion rules for transformers that ",
65+
"are not in the style guilde. Please add the rule to the style guide ",
66+
"or remove the dropping rules:", paste(diff, collapse = ", "))
67+
)
68+
}
69+
})
70+
names_line_break <- c(
71+
"set_line_break_around_comma_and_or",
72+
"set_line_break_after_assignment",
73+
"set_line_break_after_opening_if_call_is_multi_line",
74+
"set_line_break_before_closing_call",
75+
"remove_line_break_in_fun_call",
76+
"set_linebreak_after_ggplot2_plus"
77+
)
78+
expect_setequal(names(t_fun$line_break), names_line_break)
79+
80+
names_spaces <- c(
81+
"remove_space_before_closing_paren",
82+
"remove_space_before_opening_paren",
83+
"remove_space_before_comma",
84+
"spacing_around_op",
85+
"remove_space_after_opening_paren",
86+
"set_space_between_levels"
87+
)
88+
89+
expect_setequal(names(t_fun$space), names_spaces)
90+
91+
names_indention <- c("indent_braces", "indent_op", "indent_without_paren")
92+
expect_setequal(names(t_fun$indention), names_indention)
93+
94+
names_tokens <- c(
95+
"fix_quotes",
96+
if (getRversion() < 3.6) "force_assignment_op",
97+
"remove_terminal_token_before_and_after"
98+
)
99+
expect_setequal(names(t_fun$token), names_tokens)
100+
101+
})
102+
48103

49104
test_that("if no transformers_drop is specified, no transformer is removed and no error issued", {
50105
t_fun <- transformers_drop(

0 commit comments

Comments
 (0)