From e843fd5dc65f5fb06348dbcfbf2c077524e1e8a1 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 3 Dec 2024 17:31:16 +0300 Subject: [PATCH] create a new test collection instead of modifying existing tests --- .../testthat/line_breaks_and_other/curly-in.R | 9 ------ .../line_breaks_and_other/curly-out.R | 6 ---- .../pipe_and_comment-in.R | 20 ------------- .../pipe_and_comment-out.R | 12 -------- .../blank-non-strict-in.R | 4 --- .../blank-non-strict-out.R | 4 --- .../line_breaks_top_level_exprs/braces-in.R | 16 ++++++++++ .../line_breaks_top_level_exprs/braces-out.R | 11 +++++++ .../conditionals-in.R | 20 +++++++++++++ .../conditionals-out.R | 11 +++++++ .../function_defs_and_calls-in.R | 23 ++++++++++++++ .../function_defs_and_calls-out.R | 12 ++++++++ .../non_strict-in.R | 23 ++++++++++++++ .../non_strict-out.R | 12 ++++++++ .../piped_chains-in.R | 21 +++++++++++++ .../piped_chains-out.R | 10 +++++++ .../test-line_breaks_top_level_exprs.R | 30 +++++++++++++++++++ tests/testthat/test-transformers-drop.R | 2 +- 18 files changed, 190 insertions(+), 56 deletions(-) create mode 100644 tests/testthat/line_breaks_top_level_exprs/braces-in.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/braces-out.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/conditionals-in.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/conditionals-out.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-in.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-out.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/non_strict-in.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/non_strict-out.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/piped_chains-in.R create mode 100644 tests/testthat/line_breaks_top_level_exprs/piped_chains-out.R create mode 100644 tests/testthat/test-line_breaks_top_level_exprs.R diff --git a/tests/testthat/line_breaks_and_other/curly-in.R b/tests/testthat/line_breaks_and_other/curly-in.R index 31e6fc468..8da4db732 100644 --- a/tests/testthat/line_breaks_and_other/curly-in.R +++ b/tests/testthat/line_breaks_and_other/curly-in.R @@ -59,12 +59,3 @@ while (TRUE){ while (TRUE){# } - - -for (i in 1:10) {} - - - - - -while (TRUE) {} diff --git a/tests/testthat/line_breaks_and_other/curly-out.R b/tests/testthat/line_breaks_and_other/curly-out.R index 753c2a853..22730a44b 100644 --- a/tests/testthat/line_breaks_and_other/curly-out.R +++ b/tests/testthat/line_breaks_and_other/curly-out.R @@ -53,9 +53,3 @@ while (TRUE) { while (TRUE) { # } - - -for (i in 1:10) {} - - -while (TRUE) {} diff --git a/tests/testthat/line_breaks_and_other/pipe_and_comment-in.R b/tests/testthat/line_breaks_and_other/pipe_and_comment-in.R index 43970b285..f0dcfb1d5 100644 --- a/tests/testthat/line_breaks_and_other/pipe_and_comment-in.R +++ b/tests/testthat/line_breaks_and_other/pipe_and_comment-in.R @@ -1,22 +1,2 @@ 1:10 %>% # sum sum() - - -f %>% g() - - - - - -h %>% i() - - - - - -# some comment - - - - -j %>% k() diff --git a/tests/testthat/line_breaks_and_other/pipe_and_comment-out.R b/tests/testthat/line_breaks_and_other/pipe_and_comment-out.R index ed19d1149..f0dcfb1d5 100644 --- a/tests/testthat/line_breaks_and_other/pipe_and_comment-out.R +++ b/tests/testthat/line_breaks_and_other/pipe_and_comment-out.R @@ -1,14 +1,2 @@ 1:10 %>% # sum sum() - - -f %>% g() - - -h %>% i() - - -# some comment - - -j %>% k() diff --git a/tests/testthat/line_breaks_fun_call/blank-non-strict-in.R b/tests/testthat/line_breaks_fun_call/blank-non-strict-in.R index cf1631c36..21225f5f8 100644 --- a/tests/testthat/line_breaks_fun_call/blank-non-strict-in.R +++ b/tests/testthat/line_breaks_fun_call/blank-non-strict-in.R @@ -10,10 +10,6 @@ call( 1 ) - - - - call( x = 2, 1, diff --git a/tests/testthat/line_breaks_fun_call/blank-non-strict-out.R b/tests/testthat/line_breaks_fun_call/blank-non-strict-out.R index 9579dbf4d..02330a9ec 100644 --- a/tests/testthat/line_breaks_fun_call/blank-non-strict-out.R +++ b/tests/testthat/line_breaks_fun_call/blank-non-strict-out.R @@ -8,10 +8,6 @@ call( 1 ) - - - - call( x = 2, 1, diff --git a/tests/testthat/line_breaks_top_level_exprs/braces-in.R b/tests/testthat/line_breaks_top_level_exprs/braces-in.R new file mode 100644 index 000000000..d504e6413 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/braces-in.R @@ -0,0 +1,16 @@ +{ + 1 + 1 +} + + + + + +### some comment + + + + +{ + NULL +} diff --git a/tests/testthat/line_breaks_top_level_exprs/braces-out.R b/tests/testthat/line_breaks_top_level_exprs/braces-out.R new file mode 100644 index 000000000..9fd7a480d --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/braces-out.R @@ -0,0 +1,11 @@ +{ + 1 + 1 +} + + +### some comment + + +{ + NULL +} diff --git a/tests/testthat/line_breaks_top_level_exprs/conditionals-in.R b/tests/testthat/line_breaks_top_level_exprs/conditionals-in.R new file mode 100644 index 000000000..37e07e57f --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/conditionals-in.R @@ -0,0 +1,20 @@ +for (i in 1:10) {} + + + + + + +# some comment + + + + + +while (TRUE) {} + + + + +# some comment +if (TRUE) NULL diff --git a/tests/testthat/line_breaks_top_level_exprs/conditionals-out.R b/tests/testthat/line_breaks_top_level_exprs/conditionals-out.R new file mode 100644 index 000000000..54104e290 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/conditionals-out.R @@ -0,0 +1,11 @@ +for (i in 1:10) {} + + +# some comment + + +while (TRUE) {} + + +# some comment +if (TRUE) NULL diff --git a/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-in.R b/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-in.R new file mode 100644 index 000000000..4a18af903 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-in.R @@ -0,0 +1,23 @@ +f <- function() NULL + + + + + + + + +g <- function() NULL + + + + +f() + +# comment + + + + + +g() diff --git a/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-out.R b/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-out.R new file mode 100644 index 000000000..741c47309 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/function_defs_and_calls-out.R @@ -0,0 +1,12 @@ +f <- function() NULL + + +g <- function() NULL + + +f() + +# comment + + +g() diff --git a/tests/testthat/line_breaks_top_level_exprs/non_strict-in.R b/tests/testthat/line_breaks_top_level_exprs/non_strict-in.R new file mode 100644 index 000000000..4a18af903 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/non_strict-in.R @@ -0,0 +1,23 @@ +f <- function() NULL + + + + + + + + +g <- function() NULL + + + + +f() + +# comment + + + + + +g() diff --git a/tests/testthat/line_breaks_top_level_exprs/non_strict-out.R b/tests/testthat/line_breaks_top_level_exprs/non_strict-out.R new file mode 100644 index 000000000..741c47309 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/non_strict-out.R @@ -0,0 +1,12 @@ +f <- function() NULL + + +g <- function() NULL + + +f() + +# comment + + +g() diff --git a/tests/testthat/line_breaks_top_level_exprs/piped_chains-in.R b/tests/testthat/line_breaks_top_level_exprs/piped_chains-in.R new file mode 100644 index 000000000..75a3abee2 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/piped_chains-in.R @@ -0,0 +1,21 @@ + + +f %>% g() + + + + + + +h %>% i() + + + + + +# some comment + + + + +j %>% k() diff --git a/tests/testthat/line_breaks_top_level_exprs/piped_chains-out.R b/tests/testthat/line_breaks_top_level_exprs/piped_chains-out.R new file mode 100644 index 000000000..b424cbba1 --- /dev/null +++ b/tests/testthat/line_breaks_top_level_exprs/piped_chains-out.R @@ -0,0 +1,10 @@ +f %>% g() + + +h %>% i() + + +# some comment + + +j %>% k() diff --git a/tests/testthat/test-line_breaks_top_level_exprs.R b/tests/testthat/test-line_breaks_top_level_exprs.R new file mode 100644 index 000000000..dd8c95da8 --- /dev/null +++ b/tests/testthat/test-line_breaks_top_level_exprs.R @@ -0,0 +1,30 @@ +test_that("extra line breaks between conditional statements are removed", { + expect_no_warning( + test_collection("line_breaks_top_level_exprs", "conditionals", transformer = style_text) + ) +}) + +test_that("extra line breaks between function and definitions and calls are removed", { + expect_no_warning( + test_collection("line_breaks_top_level_exprs", "function_defs_and_calls", transformer = style_text) + ) +}) + +test_that("extra line breaks between piped chains are removed", { + expect_no_warning( + test_collection("line_breaks_top_level_exprs", "piped_chains", transformer = style_text) + ) +}) + +test_that("extra line breaks between braced expressions are removed", { + expect_no_warning( + test_collection("line_breaks_top_level_exprs", "braces", transformer = style_text) + ) +}) + +test_that("extra line breaks are not removed in non-strict mode", { + expect_no_warning( + test_collection("line_breaks_top_level_exprs", "non_strict", transformer = style_text) + ) +}) + diff --git a/tests/testthat/test-transformers-drop.R b/tests/testthat/test-transformers-drop.R index dfd51afda..ad10908f5 100644 --- a/tests/testthat/test-transformers-drop.R +++ b/tests/testthat/test-transformers-drop.R @@ -72,7 +72,7 @@ test_that("tidyverse transformers are correctly dropped", { names_line_break <- c( "remove_empty_lines_after_opening_and_before_closing_braces", - "set_line_breaks_between_top_level_exprs ", + "set_line_breaks_between_top_level_exprs", "set_line_break_around_comma_and_or", "set_line_break_after_assignment", "set_line_break_after_opening_if_call_is_multi_line",