Skip to content

Commit d005106

Browse files
Merge pull request #328 from lorenzwalthert/hotfix-eq-assign
- Fixing relocation of EQ_ASSIGN (#328).
2 parents 70dfa75 + 0f5a584 commit d005106

8 files changed

+83
-1
lines changed

R/relevel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ relocate_eq_assign_nest <- function(pd) {
164164
#' @param pd A parse table.
165165
find_block_id <- function(pd) {
166166
idx_eq_assign <- which(pd$token == "EQ_ASSIGN")
167-
eq_belongs_to_block <- c(0, cumsum(diff(idx_eq_assign)) > 2)
167+
eq_belongs_to_block <- c(0, cumsum(diff(idx_eq_assign) > 2))
168168

169169
empty_seq <- rep(0, nrow(pd))
170170
empty_seq[idx_eq_assign - 1] <- eq_belongs_to_block
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a = b = c = d = e = f = g = 4

tests/testthat/relocate_eq_assign/eq_assign_multiple_tokens_eq_only-in_tree

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a <- b <- c <- d <- e <- f <- g <- 4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a = b = c = d = e = f = g <- 4

tests/testthat/relocate_eq_assign/eq_assign_multiple_tokens_mixed-in_tree

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a <- b <- c <- d <- e <- f <- g <- 4

tests/testthat/test-relocate_eq_assign.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ test_that("tree hierarchy is the same no matter whether = or <- is used", {
2727
"x <- b <- 5", structure_only = TRUE
2828
)
2929
expect_equal(assign_eq, assign_left)
30+
31+
32+
assign_left_many <- create_tree(
33+
"x = b = c = d = r= 5", structure_only = TRUE
34+
)
35+
assign_eq_many <- create_tree(
36+
"x <- b <- c <- d <- r <- 5", structure_only = TRUE
37+
)
38+
expect_equal(assign_eq_many, assign_left_many)
39+
3040
})
3141

3242
test_that("braces are added in the right place in ifelse if eq_assign is in expr", {
@@ -37,6 +47,23 @@ test_that("braces are added in the right place in ifelse if eq_assign is in expr
3747
), NA)
3848
})
3949

50+
test_that("complicated reassignment works", {
51+
expect_warning(test_collection(
52+
"relocate_eq_assign", "eq_assign_multiple_tokens_eq_only",
53+
transformer = style_text,
54+
scope = "tokens",
55+
style = tidyverse_style
56+
), NA)
57+
58+
expect_warning(test_collection(
59+
"relocate_eq_assign", "eq_assign_multiple_tokens_mixed",
60+
transformer = style_text,
61+
scope = "tokens",
62+
style = tidyverse_style
63+
), NA)
64+
})
65+
66+
4067
test_that("eq_assign is not replaced", {
4168
expect_warning(test_collection(
4269
"relocate_eq_assign", "eq_assign_ifelse_scope_line_breaks",

0 commit comments

Comments
 (0)