diff --git a/R/get_transformers.R b/R/get_transformers.R index 55e57b196..04cce9f63 100644 --- a/R/get_transformers.R +++ b/R/get_transformers.R @@ -39,6 +39,7 @@ get_transformers_flat <- function(strict = TRUE, remove_space_before_comma, remove_space_after_opening_paren, remove_space_after_excl, + remove_space_before_dollar, partial(start_comments_with_space, force_one = start_comments_with_one_space), NULL) @@ -85,6 +86,7 @@ get_transformers_nested <- function( partial(indent_round, indent_by = indent_by), partial(indent_curly, indent_by = indent_by), partial(indent_op, indent_by = indent_by), + partial(indent_eq_sub, indent_by = indent_by), partial(indent_without_paren, indent_by = indent_by), get_transformers_flat(strict, start_comments_with_one_space), remove_space_after_unary_pm_nested, diff --git a/R/modify_pd.R b/R/modify_pd.R index 2c933d224..23c780ac5 100644 --- a/R/modify_pd.R +++ b/R/modify_pd.R @@ -21,15 +21,31 @@ indent_curly <- function(pd, indent_by) { set_unindention_child(pd, token = "'}'", unindent_by = indent_by) } -#' @rdname update_indention -indent_op <- function(pd, indent_by, token = c(math_token, - "SPECIAL-PIPE", - "LEFT_ASSIGN")) { +#' @describeIn update_indention Indents operatos +indent_op <- function(pd, + indent_by, + token = c(math_token, + logical_token, + special_token, + "LEFT_ASSIGN", + "'$'")) { indent_indices <- compute_indent_indices(pd, token, indent_last = TRUE) pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by pd } +#' @describeIn update_indention Upates indention for token EQ_SUB. Only differs +#' from ident_op in the sense that the last token on the talbe where EQ_SUB +#' occurs is not indented (see[compute_indent_indices()]) +indent_eq_sub <- function(pd, + indent_by, + token = "EQ_SUB") { + indent_indices <- compute_indent_indices(pd, token, indent_last = FALSE) + pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by + pd +} + + #' @describeIn update_indention Same as indent_op, but only indents one token #' after `token`, not all remaining. indent_assign <- function(pd, indent_by, token = NULL) { @@ -117,7 +133,7 @@ token_is_multi_line <- function(pd) { #' (R/rules-line_break.R) but we need `newlines` to determine #' whether or not to set `spaces` (R/rules-spacing.R), we have to update the #' attribute. We cannot simply use `dplyr::lead(pd$lag_newlines)` since we would -#' loose information for the last token. `spaces` is left as is in +#' lose information for the last token. `spaces` is left as is in #' R/rules-spacing.R for tokens at the end of a line since this allows styling #' without touching indention. #' @param pd A parse table. diff --git a/R/relevel.R b/R/relevel.R index 178714de4..824d72676 100644 --- a/R/relevel.R +++ b/R/relevel.R @@ -20,8 +20,8 @@ flatten_operators <- function(pd_nested) { #' @param pd_nested A nested parse table. #' @include token.R flatten_operators_one <- function(pd_nested) { - pd_token_left <- c(special_token, math_token) - pd_token_right <- c(special_token, left_assignment_token, "'+'", "'-'") + pd_token_left <- c(special_token, math_token, "'$'") + pd_token_right <- c(special_token, "LEFT_ASSIGN", "'+'", "'-'") bound <- pd_nested %>% flatten_pd(pd_token_left, left = TRUE) %>% flatten_pd(pd_token_right, left = FALSE) diff --git a/R/rules-spacing.R b/R/rules-spacing.R index 93a778454..301a85c8c 100644 --- a/R/rules-spacing.R +++ b/R/rules-spacing.R @@ -189,3 +189,11 @@ remove_space_after_excl <- function(pd_flat) { pd_flat$spaces[excl] <- 0L pd_flat } + + +remove_space_before_dollar <- function(pd_flat) { + dollar_after <- (pd_flat$token == "'$'") & (pd_flat$lag_newlines == 0L) + dollar_before <- lead(dollar_after, default = FALSE) + pd_flat$spaces[dollar_before] <- 0L + pd_flat +} diff --git a/R/token.R b/R/token.R index 927ac9571..f5bbdc30c 100644 --- a/R/token.R +++ b/R/token.R @@ -10,6 +10,7 @@ token <- tribble( ">=" , "logical" , "GE", "!=" , "logical" , "NE", "==" , "logical" , "EQ", + "=" , "assign_left" , "EQ_SUB", "=" , "assign_left" , "EQ_ASSIGN", "<-" , "assign_left" , "LEFT_ASSIGN", "->" , "assign_right", "RIGHT_ASSIGN", diff --git a/man/update_indention.Rd b/man/update_indention.Rd index af9bb0f66..13df62a93 100644 --- a/man/update_indention.Rd +++ b/man/update_indention.Rd @@ -5,6 +5,7 @@ \alias{indent_round} \alias{indent_curly} \alias{indent_op} +\alias{indent_eq_sub} \alias{indent_assign} \alias{indent_without_paren} \title{Update indention information of parse data} @@ -13,7 +14,10 @@ indent_round(pd, indent_by) indent_curly(pd, indent_by) -indent_op(pd, indent_by, token = c(math_token, "SPECIAL-PIPE", "LEFT_ASSIGN")) +indent_op(pd, indent_by, token = c(math_token, logical_token, special_token, + "LEFT_ASSIGN", "'$'")) + +indent_eq_sub(pd, indent_by, token = "EQ_SUB") indent_assign(pd, indent_by, token = NULL) @@ -34,6 +38,12 @@ Update indention information of parse data \itemize{ \item \code{indent_round}: Inserts indetion based on round brackets. +\item \code{indent_op}: Indents operatos + +\item \code{indent_eq_sub}: Upates indention for token EQ_SUB. Only differs +from ident_op in the sense that the last token on the talbe where EQ_SUB +occurs is not indented (see\code{\link[=compute_indent_indices]{compute_indent_indices()}}) + \item \code{indent_assign}: Same as indent_op, but only indents one token after \code{token}, not all remaining. diff --git a/man/update_newlines.Rd b/man/update_newlines.Rd index 0163089b0..b0e8d0ad2 100644 --- a/man/update_newlines.Rd +++ b/man/update_newlines.Rd @@ -17,7 +17,7 @@ As we work only with the \code{lag_newlines} attribute for setting the linebreak (R/rules-line_break.R) but we need \code{newlines} to determine whether or not to set \code{spaces} (R/rules-spacing.R), we have to update the attribute. We cannot simply use \code{dplyr::lead(pd$lag_newlines)} since we would -loose information for the last token. \code{spaces} is left as is in +lose information for the last token. \code{spaces} is left as is in R/rules-spacing.R for tokens at the end of a line since this allows styling without touching indention. } diff --git a/tests/testthat/indention_multiple/overall-in_tree b/tests/testthat/indention_multiple/overall-in_tree index c3648b9a7..607f36433 100644 --- a/tests/testthat/indention_multiple/overall-in_tree +++ b/tests/testthat/indention_multiple/overall-in_tree @@ -1,18 +1,18 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) - ¦--COMMENT: #'thi [0/0] {1} + ¦--COMMENT: #' th [0/0] {1} ¦--COMMENT: #' [1/0] {4} ¦--COMMENT: #' @p [1/0] {7} ¦--COMMENT: #' [1/0] {10} - ¦--expr: [1/0] {246} - ¦ ¦--expr: [0/0] {15} + ¦--expr: [1/0] {247} + ¦ ¦--expr: [0/1] {15} ¦ ¦ °--SYMBOL: a [0/0] {13} ¦ ¦--LEFT_ASSIGN: <- [0/1] {14} - ¦ °--expr: [0/0] {245} + ¦ °--expr: [0/0] {246} ¦ ¦--FUNCTION: funct [0/0] {16} ¦ ¦--'(': ( [0/0] {17} ¦ ¦--SYMBOL_FORMALS: x [0/0] {18} - ¦ ¦--')': ) [0/0] {19} - ¦ °--expr: [0/0] {242} + ¦ ¦--')': ) [0/1] {19} + ¦ °--expr: [0/0] {243} ¦ ¦--'{': { [0/2] {21} ¦ ¦--expr: [1/2] {123} ¦ ¦ ¦--expr: [0/0] {25} @@ -20,8 +20,8 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) ¦ ¦ ¦--'(': ( [0/0] {24} ¦ ¦ ¦--expr: [0/0] {28} ¦ ¦ ¦ °--STR_CONST: "I wa [0/0] {26} - ¦ ¦ ¦--',': , [0/0] {27} - ¦ ¦ ¦--expr: [0/5] {119} + ¦ ¦ ¦--',': , [0/1] {27} + ¦ ¦ ¦--expr: [0/0] {119} ¦ ¦ ¦ ¦--'{': { [0/4] {31} ¦ ¦ ¦ ¦--expr: [1/4] {64} ¦ ¦ ¦ ¦ ¦--expr: [0/1] {35} @@ -33,7 +33,7 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) ¦ ¦ ¦ ¦ ¦--'(': ( [0/0] {37} ¦ ¦ ¦ ¦ ¦--expr: [0/0] {40} ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {39} - ¦ ¦ ¦ ¦ ¦--',': , [0/0] {41} + ¦ ¦ ¦ ¦ ¦--',': , [0/1] {41} ¦ ¦ ¦ ¦ ¦--expr: [0/0] {58} ¦ ¦ ¦ ¦ ¦ ¦--expr: [0/0] {46} ¦ ¦ ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {44} @@ -41,7 +41,7 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) ¦ ¦ ¦ ¦ ¦ ¦--expr: [1/4] {55} ¦ ¦ ¦ ¦ ¦ ¦ ¦--expr: [0/1] {49} ¦ ¦ ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 22 [0/0] {48} - ¦ ¦ ¦ ¦ ¦ ¦ ¦--'+': + [0/0] {50} + ¦ ¦ ¦ ¦ ¦ ¦ ¦--'+': + [0/1] {50} ¦ ¦ ¦ ¦ ¦ ¦ °--expr: [0/0] {52} ¦ ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {51} ¦ ¦ ¦ ¦ ¦ °--')': ) [1/0] {54} @@ -81,74 +81,74 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) ¦ ¦ ¦ ¦ °--'}': } [1/0] {110} ¦ ¦ ¦ °--'}': } [1/0] {114} ¦ ¦ °--')': ) [0/0] {120} - ¦ ¦--COMMENT: #we l [1/2] {127} - ¦ ¦--expr: [1/2] {188} + ¦ ¦--COMMENT: # we [1/2] {127} + ¦ ¦--expr: [1/2] {189} ¦ ¦ ¦--expr: [0/0] {132} ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {130} - ¦ ¦ ¦--'(': ( [0/0] {131} - ¦ ¦ ¦--expr: [0/0] {145} - ¦ ¦ ¦ ¦--expr: [0/0] {135} - ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: list [0/0] {133} - ¦ ¦ ¦ ¦--'(': ( [0/0] {134} - ¦ ¦ ¦ ¦--expr: [0/0] {142} - ¦ ¦ ¦ ¦ ¦--expr: [0/1] {138} - ¦ ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {136} - ¦ ¦ ¦ ¦ ¦--'+': + [0/1] {137} - ¦ ¦ ¦ ¦ °--expr: [0/0] {140} - ¦ ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {139} - ¦ ¦ ¦ °--')': ) [0/0] {141} - ¦ ¦ ¦--',': , [0/4] {146} - ¦ ¦ ¦--expr: [1/1] {184} - ¦ ¦ ¦ ¦--expr: [0/0] {152} - ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {150} - ¦ ¦ ¦ ¦--'(': ( [0/4] {151} - ¦ ¦ ¦ ¦--expr: [0/3] {180} - ¦ ¦ ¦ ¦ ¦--expr: [0/0] {155} - ¦ ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {153} - ¦ ¦ ¦ ¦ ¦--'(': ( [0/6] {154} - ¦ ¦ ¦ ¦ ¦--expr: [1/0] {163} - ¦ ¦ ¦ ¦ ¦ ¦--expr: [0/1] {158} - ¦ ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 26 [0/0] {157} - ¦ ¦ ¦ ¦ ¦ ¦--'^': ^ [0/1] {159} - ¦ ¦ ¦ ¦ ¦ °--expr: [0/0] {161} - ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {160} - ¦ ¦ ¦ ¦ ¦--',': , [0/1] {162} - ¦ ¦ ¦ ¦ ¦--COMMENT: # FIX [0/6] {166} - ¦ ¦ ¦ ¦ ¦--expr: [1/0] {169} - ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 8 [0/0] {168} - ¦ ¦ ¦ ¦ ¦--',': , [0/6] {170} - ¦ ¦ ¦ ¦ ¦--expr: [1/4] {175} - ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 7 [0/0] {174} - ¦ ¦ ¦ ¦ °--')': ) [1/0] {177} - ¦ ¦ ¦ °--')': ) [0/0] {181} - ¦ ¦ °--')': ) [0/0] {185} - ¦ ¦--expr: [2/0] {236} - ¦ ¦ ¦--expr: [0/0] {196} - ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: call [0/0] {194} - ¦ ¦ ¦--'(': ( [0/4] {195} - ¦ ¦ ¦--expr: [1/0] {199} - ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {198} - ¦ ¦ ¦--',': , [0/1] {200} - ¦ ¦ ¦--expr: [0/0] {204} - ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {203} - ¦ ¦ ¦--',': , [0/4] {205} - ¦ ¦ ¦--expr: [1/0] {219} - ¦ ¦ ¦ ¦--expr: [0/0] {210} - ¦ ¦ ¦ ¦ °--NUM_CONST: 23 [0/0] {209} - ¦ ¦ ¦ ¦--'+': + [0/0] {211} - ¦ ¦ ¦ ¦--expr: [0/1] {213} - ¦ ¦ ¦ ¦ °--NUM_CONST: Inf [0/0] {212} - ¦ ¦ ¦ ¦--'-': - [0/1] {214} - ¦ ¦ ¦ °--expr: [0/0] {217} - ¦ ¦ ¦ °--NUM_CONST: 99 [0/0] {216} - ¦ ¦ ¦--',': , [0/1] {218} - ¦ ¦ ¦--expr: [0/0] {232} - ¦ ¦ ¦ ¦--expr: [0/0] {224} - ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: call [0/0] {222} - ¦ ¦ ¦ ¦--'(': ( [0/6] {223} - ¦ ¦ ¦ ¦--expr: [1/4] {227} - ¦ ¦ ¦ ¦ °--NUM_CONST: 16 [0/0] {226} - ¦ ¦ ¦ °--')': ) [1/0] {229} - ¦ ¦ °--')': ) [0/0] {233} - ¦ °--'}': } [1/0] {240} - °--COMMENT: # com [1/0] {249} + ¦ ¦ ¦--'(': ( [0/4] {131} + ¦ ¦ ¦--expr: [1/0] {146} + ¦ ¦ ¦ ¦--expr: [0/0] {136} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: list [0/0] {134} + ¦ ¦ ¦ ¦--'(': ( [0/0] {135} + ¦ ¦ ¦ ¦--expr: [0/0] {143} + ¦ ¦ ¦ ¦ ¦--expr: [0/1] {139} + ¦ ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {137} + ¦ ¦ ¦ ¦ ¦--'+': + [0/1] {138} + ¦ ¦ ¦ ¦ °--expr: [0/0] {141} + ¦ ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {140} + ¦ ¦ ¦ °--')': ) [0/0] {142} + ¦ ¦ ¦--',': , [0/4] {147} + ¦ ¦ ¦--expr: [1/0] {185} + ¦ ¦ ¦ ¦--expr: [0/0] {153} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {151} + ¦ ¦ ¦ ¦--'(': ( [0/0] {152} + ¦ ¦ ¦ ¦--expr: [0/0] {181} + ¦ ¦ ¦ ¦ ¦--expr: [0/0] {156} + ¦ ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: c [0/0] {154} + ¦ ¦ ¦ ¦ ¦--'(': ( [0/6] {155} + ¦ ¦ ¦ ¦ ¦--expr: [1/0] {164} + ¦ ¦ ¦ ¦ ¦ ¦--expr: [0/1] {159} + ¦ ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 26 [0/0] {158} + ¦ ¦ ¦ ¦ ¦ ¦--'^': ^ [0/1] {160} + ¦ ¦ ¦ ¦ ¦ °--expr: [0/0] {162} + ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {161} + ¦ ¦ ¦ ¦ ¦--',': , [0/1] {163} + ¦ ¦ ¦ ¦ ¦--COMMENT: # FIX [0/6] {167} + ¦ ¦ ¦ ¦ ¦--expr: [1/0] {170} + ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 8 [0/0] {169} + ¦ ¦ ¦ ¦ ¦--',': , [0/6] {171} + ¦ ¦ ¦ ¦ ¦--expr: [1/2] {176} + ¦ ¦ ¦ ¦ ¦ °--NUM_CONST: 7 [0/0] {175} + ¦ ¦ ¦ ¦ °--')': ) [1/0] {178} + ¦ ¦ ¦ °--')': ) [0/0] {182} + ¦ ¦ °--')': ) [0/0] {186} + ¦ ¦--expr: [2/0] {237} + ¦ ¦ ¦--expr: [0/0] {197} + ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: call [0/0] {195} + ¦ ¦ ¦--'(': ( [0/4] {196} + ¦ ¦ ¦--expr: [1/0] {200} + ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {199} + ¦ ¦ ¦--',': , [0/1] {201} + ¦ ¦ ¦--expr: [0/0] {205} + ¦ ¦ ¦ °--NUM_CONST: 2 [0/0] {204} + ¦ ¦ ¦--',': , [0/4] {206} + ¦ ¦ ¦--expr: [1/0] {220} + ¦ ¦ ¦ ¦--expr: [0/1] {211} + ¦ ¦ ¦ ¦ °--NUM_CONST: 23 [0/0] {210} + ¦ ¦ ¦ ¦--'+': + [0/1] {212} + ¦ ¦ ¦ ¦--expr: [0/1] {214} + ¦ ¦ ¦ ¦ °--NUM_CONST: Inf [0/0] {213} + ¦ ¦ ¦ ¦--'-': - [0/1] {215} + ¦ ¦ ¦ °--expr: [0/0] {218} + ¦ ¦ ¦ °--NUM_CONST: 99 [0/0] {217} + ¦ ¦ ¦--',': , [0/1] {219} + ¦ ¦ ¦--expr: [0/0] {233} + ¦ ¦ ¦ ¦--expr: [0/0] {225} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: call [0/0] {223} + ¦ ¦ ¦ ¦--'(': ( [0/6] {224} + ¦ ¦ ¦ ¦--expr: [1/2] {228} + ¦ ¦ ¦ ¦ °--NUM_CONST: 16 [0/0] {227} + ¦ ¦ ¦ °--')': ) [1/0] {230} + ¦ ¦ °--')': ) [0/0] {234} + ¦ °--'}': } [1/0] {241} + °--COMMENT: # com [1/0] {250} diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index 55f400060..50e228294 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -14,7 +14,8 @@ a <- function(x) { } }) # we like comments too - c(list(x + 2), + c( + list(x + 2), c(c( 26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple 8, diff --git a/tests/testthat/indention_operators/dollar_R6-in.R b/tests/testthat/indention_operators/dollar_R6-in.R new file mode 100644 index 000000000..de575d6a5 --- /dev/null +++ b/tests/testthat/indention_operators/dollar_R6-in.R @@ -0,0 +1,4 @@ + x$ + add(10) $ +add(10)$sum + +3 diff --git a/tests/testthat/indention_operators/dollar_R6-in_tree b/tests/testthat/indention_operators/dollar_R6-in_tree new file mode 100644 index 000000000..035173d31 --- /dev/null +++ b/tests/testthat/indention_operators/dollar_R6-in_tree @@ -0,0 +1,25 @@ +ROOT (token: short_text [lag_newlines/spaces] {id}) + °--expr: [0/0] {33} + ¦--expr: [0/0] {24} + ¦ ¦--expr: [0/0] {17} + ¦ ¦ ¦--expr: [0/2] {13} + ¦ ¦ ¦ ¦--expr: [0/0] {6} + ¦ ¦ ¦ ¦ ¦--expr: [0/0] {3} + ¦ ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {1} + ¦ ¦ ¦ ¦ ¦--'$': $ [0/3] {2} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: add [1/0] {5} + ¦ ¦ ¦ ¦--'(': ( [0/0] {7} + ¦ ¦ ¦ ¦--expr: [0/0] {9} + ¦ ¦ ¦ ¦ °--NUM_CONST: 10 [0/0] {8} + ¦ ¦ ¦ °--')': ) [0/0] {10} + ¦ ¦ ¦--'$': $ [0/0] {14} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: add [1/0] {16} + ¦ ¦--'(': ( [0/0] {18} + ¦ ¦--expr: [0/0] {20} + ¦ ¦ °--NUM_CONST: 10 [0/0] {19} + ¦ °--')': ) [0/0] {21} + ¦--'$': $ [0/0] {25} + ¦--SYMBOL: sum [0/1] {26} + ¦--'+': + [0/0] {28} + °--expr: [1/0] {31} + °--NUM_CONST: 3 [0/0] {30} diff --git a/tests/testthat/indention_operators/dollar_R6-out.R b/tests/testthat/indention_operators/dollar_R6-out.R new file mode 100644 index 000000000..e4cf03219 --- /dev/null +++ b/tests/testthat/indention_operators/dollar_R6-out.R @@ -0,0 +1,4 @@ +x$ + add(10)$ + add(10)$sum + + 3 diff --git a/tests/testthat/indention_operators/logical_special_eq_sub-in.R b/tests/testthat/indention_operators/logical_special_eq_sub-in.R new file mode 100644 index 000000000..8eb76753d --- /dev/null +++ b/tests/testthat/indention_operators/logical_special_eq_sub-in.R @@ -0,0 +1,16 @@ +a || +b + + a > +4 + +a& +3 + +b %in% + c + +data_frame( +a = + list() + ) diff --git a/tests/testthat/indention_operators/logical_special_eq_sub-in_tree b/tests/testthat/indention_operators/logical_special_eq_sub-in_tree new file mode 100644 index 000000000..68a307df9 --- /dev/null +++ b/tests/testthat/indention_operators/logical_special_eq_sub-in_tree @@ -0,0 +1,37 @@ +ROOT (token: short_text [lag_newlines/spaces] {id}) + ¦--expr: [0/2] {8} + ¦ ¦--expr: [0/1] {3} + ¦ ¦ °--SYMBOL: a [0/0] {1} + ¦ ¦--OR2: || [0/0] {2} + ¦ °--expr: [1/0] {7} + ¦ °--SYMBOL: b [0/0] {5} + ¦--expr: [2/0] {20} + ¦ ¦--expr: [0/1] {15} + ¦ ¦ °--SYMBOL: a [0/0] {13} + ¦ ¦--GT: > [0/0] {14} + ¦ °--expr: [1/0] {18} + ¦ °--NUM_CONST: 4 [0/0] {17} + ¦--expr: [2/0] {32} + ¦ ¦--expr: [0/0] {27} + ¦ ¦ °--SYMBOL: a [0/0] {25} + ¦ ¦--AND: & [0/0] {26} + ¦ °--expr: [1/0] {30} + ¦ °--NUM_CONST: 3 [0/0] {29} + ¦--expr: [2/0] {44} + ¦ ¦--expr: [0/1] {39} + ¦ ¦ °--SYMBOL: b [0/0] {37} + ¦ ¦--SPECIAL-IN: %in% [0/1] {38} + ¦ °--expr: [1/0] {43} + ¦ °--SYMBOL: c [0/0] {41} + °--expr: [2/0] {66} + ¦--expr: [0/0] {51} + ¦ °--SYMBOL_FUNCTION_CALL: data_ [0/0] {49} + ¦--'(': ( [0/0] {50} + ¦--SYMBOL_SUB: a [1/5] {53} + ¦--EQ_SUB: = [0/6] {54} + ¦--expr: [1/1] {61} + ¦ ¦--expr: [0/0] {58} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: list [0/0] {56} + ¦ ¦--'(': ( [0/0] {57} + ¦ °--')': ) [0/0] {59} + °--')': ) [1/0] {63} diff --git a/tests/testthat/indention_operators/logical_special_eq_sub-out.R b/tests/testthat/indention_operators/logical_special_eq_sub-out.R new file mode 100644 index 000000000..0641bcef5 --- /dev/null +++ b/tests/testthat/indention_operators/logical_special_eq_sub-out.R @@ -0,0 +1,16 @@ +a || + b + +a > + 4 + +a & + 3 + +b %in% + c + +data_frame( + a = + list() +) diff --git a/tests/testthat/line_breaks_and_other/curly-in_tree b/tests/testthat/line_breaks_and_other/curly-in_tree index ff3fe7e44..7a31453b5 100644 --- a/tests/testthat/line_breaks_and_other/curly-in_tree +++ b/tests/testthat/line_breaks_and_other/curly-in_tree @@ -1,114 +1,113 @@ ROOT (token: short_text [lag_newlines/spaces] {id}) - ¦--COMMENT: # FIX [0/0] {1} - ¦--COMMENT: # { n [1/0] {4} - ¦--expr: [1/0] {42} - ¦ ¦--IF: if [0/1] {7} - ¦ ¦--'(': ( [0/0] {8} - ¦ ¦--expr: [0/0] {15} - ¦ ¦ ¦--expr: [0/1] {11} - ¦ ¦ ¦ °--SYMBOL: y [0/0] {9} - ¦ ¦ ¦--EQ: == [0/1] {10} - ¦ ¦ °--expr: [0/0] {13} - ¦ ¦ °--NUM_CONST: 0 [0/0] {12} - ¦ ¦--')': ) [0/0] {14} - ¦ ¦--expr: [1/1] {27} - ¦ ¦ ¦--'{': { [0/2] {18} - ¦ ¦ ¦--expr: [1/0] {21} - ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {20} - ¦ ¦ °--'}': } [1/0] {25} - ¦ ¦--ELSE: else [0/1] {28} - ¦ °--expr: [0/0] {39} - ¦ ¦--'{': { [0/2] {30} - ¦ ¦--expr: [1/0] {33} - ¦ ¦ °--NUM_CONST: 2 [0/0] {32} - ¦ °--'}': } [1/0] {37} - ¦--expr: [2/0] {76} + ¦--COMMENT: # { n [0/0] {1} + ¦--expr: [1/0] {39} + ¦ ¦--IF: if [0/1] {4} + ¦ ¦--'(': ( [0/0] {5} + ¦ ¦--expr: [0/0] {12} + ¦ ¦ ¦--expr: [0/1] {8} + ¦ ¦ ¦ °--SYMBOL: y [0/0] {6} + ¦ ¦ ¦--EQ: == [0/1] {7} + ¦ ¦ °--expr: [0/0] {10} + ¦ ¦ °--NUM_CONST: 0 [0/0] {9} + ¦ ¦--')': ) [0/0] {11} + ¦ ¦--expr: [1/1] {24} + ¦ ¦ ¦--'{': { [0/2] {15} + ¦ ¦ ¦--expr: [1/0] {18} + ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {17} + ¦ ¦ °--'}': } [1/0] {22} + ¦ ¦--ELSE: else [0/1] {25} + ¦ °--expr: [0/0] {36} + ¦ ¦--'{': { [0/2] {27} + ¦ ¦--expr: [1/0] {30} + ¦ ¦ °--NUM_CONST: 2 [0/0] {29} + ¦ °--'}': } [1/0] {34} + ¦--expr: [2/0] {73} + ¦ ¦--expr: [0/0] {46} + ¦ ¦ °--SYMBOL_FUNCTION_CALL: test_ [0/0] {44} + ¦ ¦--'(': ( [0/0] {45} ¦ ¦--expr: [0/0] {49} - ¦ ¦ °--SYMBOL_FUNCTION_CALL: test_ [0/0] {47} - ¦ ¦--'(': ( [0/0] {48} - ¦ ¦--expr: [0/0] {52} - ¦ ¦ °--STR_CONST: "I am [0/0] {50} - ¦ ¦--',': , [0/10] {51} - ¦ ¦--expr: [1/0] {72} - ¦ ¦ ¦--'{': { [0/12] {56} - ¦ ¦ ¦--expr: [1/10] {66} + ¦ ¦ °--STR_CONST: "I am [0/0] {47} + ¦ ¦--',': , [0/10] {48} + ¦ ¦--expr: [1/0] {69} + ¦ ¦ ¦--'{': { [0/12] {53} + ¦ ¦ ¦--expr: [1/10] {63} + ¦ ¦ ¦ ¦--expr: [0/0] {57} + ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: a_tes [0/0] {55} + ¦ ¦ ¦ ¦--'(': ( [0/0] {56} ¦ ¦ ¦ ¦--expr: [0/0] {60} - ¦ ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: a_tes [0/0] {58} - ¦ ¦ ¦ ¦--'(': ( [0/0] {59} - ¦ ¦ ¦ ¦--expr: [0/0] {63} - ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {61} - ¦ ¦ ¦ °--')': ) [0/0] {62} - ¦ ¦ °--'}': } [1/0] {70} - ¦ °--')': ) [0/0] {73} - ¦--COMMENT: # A { [3/0] {84} - ¦--expr: [1/0] {108} - ¦ ¦--IF: if [0/1] {87} - ¦ ¦--'(': ( [0/0] {88} - ¦ ¦--expr: [0/0] {95} - ¦ ¦ ¦--expr: [0/1] {91} - ¦ ¦ ¦ °--SYMBOL: x [0/0] {89} - ¦ ¦ ¦--GT: > [0/1] {90} - ¦ ¦ °--expr: [0/0] {93} - ¦ ¦ °--NUM_CONST: 3 [0/0] {92} - ¦ ¦--')': ) [0/1] {94} - ¦ °--expr: [0/0] {105} - ¦ ¦--'{': { [0/1] {97} - ¦ ¦--expr: [0/0] {100} - ¦ ¦ °--STR_CONST: "x" [0/0] {98} - ¦ °--'}': } [1/0] {103} - ¦--COMMENT: # A } [2/0] {113} - ¦--expr: [1/0] {136} - ¦ ¦--IF: if [0/1] {116} - ¦ ¦--'(': ( [0/0] {117} - ¦ ¦--expr: [0/0] {124} - ¦ ¦ ¦--expr: [0/1] {120} - ¦ ¦ ¦ °--SYMBOL: x [0/0] {118} - ¦ ¦ ¦--GT: > [0/1] {119} - ¦ ¦ °--expr: [0/0] {122} - ¦ ¦ °--NUM_CONST: 3 [0/0] {121} - ¦ ¦--')': ) [0/1] {123} - ¦ °--expr: [0/0] {133} - ¦ ¦--'{': { [0/2] {126} - ¦ ¦--expr: [1/0] {130} - ¦ ¦ °--STR_CONST: "x" [0/0] {128} - ¦ °--'}': } [0/0] {129} - ¦--COMMENT: # ELS [2/0] {141} - ¦--expr: [1/0] {178} - ¦ ¦--IF: if [0/1] {144} - ¦ ¦--'(': ( [0/0] {145} - ¦ ¦--expr: [0/0] {152} - ¦ ¦ ¦--expr: [0/1] {147} - ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {146} - ¦ ¦ ¦--GT: > [0/1] {148} - ¦ ¦ °--expr: [0/0] {150} - ¦ ¦ °--NUM_CONST: 3 [0/0] {149} - ¦ ¦--')': ) [0/1] {151} - ¦ ¦--expr: [0/1] {163} - ¦ ¦ ¦--'{': { [0/2] {154} - ¦ ¦ ¦--expr: [1/0] {158} - ¦ ¦ ¦ °--STR_CONST: "x" [0/0] {156} - ¦ ¦ °--'}': } [1/0] {161} - ¦ ¦--ELSE: else [0/1] {164} - ¦ °--expr: [0/0] {175} - ¦ ¦--'{': { [0/2] {166} - ¦ ¦--expr: [1/0] {170} - ¦ ¦ °--STR_CONST: "y" [0/0] {168} - ¦ °--'}': } [1/0] {173} - °--expr: [2/0] {212} + ¦ ¦ ¦ ¦ °--SYMBOL: x [0/0] {58} + ¦ ¦ ¦ °--')': ) [0/0] {59} + ¦ ¦ °--'}': } [1/0] {67} + ¦ °--')': ) [0/0] {70} + ¦--COMMENT: # A { [3/0] {81} + ¦--expr: [1/0] {105} + ¦ ¦--IF: if [0/1] {84} + ¦ ¦--'(': ( [0/0] {85} + ¦ ¦--expr: [0/0] {92} + ¦ ¦ ¦--expr: [0/1] {88} + ¦ ¦ ¦ °--SYMBOL: x [0/0] {86} + ¦ ¦ ¦--GT: > [0/1] {87} + ¦ ¦ °--expr: [0/0] {90} + ¦ ¦ °--NUM_CONST: 3 [0/0] {89} + ¦ ¦--')': ) [0/1] {91} + ¦ °--expr: [0/0] {102} + ¦ ¦--'{': { [0/1] {94} + ¦ ¦--expr: [0/0] {97} + ¦ ¦ °--STR_CONST: "x" [0/0] {95} + ¦ °--'}': } [1/0] {100} + ¦--COMMENT: # A } [2/0] {110} + ¦--expr: [1/0] {133} + ¦ ¦--IF: if [0/1] {113} + ¦ ¦--'(': ( [0/0] {114} + ¦ ¦--expr: [0/0] {121} + ¦ ¦ ¦--expr: [0/1] {117} + ¦ ¦ ¦ °--SYMBOL: x [0/0] {115} + ¦ ¦ ¦--GT: > [0/1] {116} + ¦ ¦ °--expr: [0/0] {119} + ¦ ¦ °--NUM_CONST: 3 [0/0] {118} + ¦ ¦--')': ) [0/1] {120} + ¦ °--expr: [0/0] {130} + ¦ ¦--'{': { [0/2] {123} + ¦ ¦--expr: [1/0] {127} + ¦ ¦ °--STR_CONST: "x" [0/0] {125} + ¦ °--'}': } [0/0] {126} + ¦--COMMENT: # ELS [2/0] {138} + ¦--expr: [1/0] {175} + ¦ ¦--IF: if [0/1] {141} + ¦ ¦--'(': ( [0/0] {142} + ¦ ¦--expr: [0/0] {149} + ¦ ¦ ¦--expr: [0/1] {144} + ¦ ¦ ¦ °--NUM_CONST: 1 [0/0] {143} + ¦ ¦ ¦--GT: > [0/1] {145} + ¦ ¦ °--expr: [0/0] {147} + ¦ ¦ °--NUM_CONST: 3 [0/0] {146} + ¦ ¦--')': ) [0/1] {148} + ¦ ¦--expr: [0/1] {160} + ¦ ¦ ¦--'{': { [0/2] {151} + ¦ ¦ ¦--expr: [1/0] {155} + ¦ ¦ ¦ °--STR_CONST: "x" [0/0] {153} + ¦ ¦ °--'}': } [1/0] {158} + ¦ ¦--ELSE: else [0/1] {161} + ¦ °--expr: [0/0] {172} + ¦ ¦--'{': { [0/2] {163} + ¦ ¦--expr: [1/0] {167} + ¦ ¦ °--STR_CONST: "y" [0/0] {165} + ¦ °--'}': } [1/0] {170} + °--expr: [2/0] {209} + ¦--expr: [0/0] {182} + ¦ °--SYMBOL_FUNCTION_CALL: test_ [0/0] {180} + ¦--'(': ( [0/0] {181} ¦--expr: [0/0] {185} - ¦ °--SYMBOL_FUNCTION_CALL: test_ [0/0] {183} - ¦--'(': ( [0/0] {184} - ¦--expr: [0/0] {188} - ¦ °--STR_CONST: "I am [0/0] {186} - ¦--',': , [0/1] {187} - ¦--expr: [0/0] {207} - ¦ ¦--'{': { [0/2] {191} - ¦ ¦--expr: [1/0] {201} + ¦ °--STR_CONST: "I am [0/0] {183} + ¦--',': , [0/1] {184} + ¦--expr: [0/0] {204} + ¦ ¦--'{': { [0/2] {188} + ¦ ¦--expr: [1/0] {198} + ¦ ¦ ¦--expr: [0/0] {192} + ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: a_tes [0/0] {190} + ¦ ¦ ¦--'(': ( [0/0] {191} ¦ ¦ ¦--expr: [0/0] {195} - ¦ ¦ ¦ °--SYMBOL_FUNCTION_CALL: a_tes [0/0] {193} - ¦ ¦ ¦--'(': ( [0/0] {194} - ¦ ¦ ¦--expr: [0/0] {198} - ¦ ¦ ¦ °--SYMBOL: x [0/0] {196} - ¦ ¦ °--')': ) [0/0] {197} - ¦ °--'}': } [1/0] {205} - °--')': ) [1/0] {209} + ¦ ¦ ¦ °--SYMBOL: x [0/0] {193} + ¦ ¦ °--')': ) [0/0] {194} + ¦ °--'}': } [1/0] {202} + °--')': ) [1/0] {206} diff --git a/tests/testthat/test-indention_operators.R b/tests/testthat/test-indention_operators.R index 0b74ce199..f95fce1a9 100644 --- a/tests/testthat/test-indention_operators.R +++ b/tests/testthat/test-indention_operators.R @@ -24,6 +24,18 @@ test_that("while / for / if without curly brackets", { transformer = style_text), NA) }) +test_that("logical, special and EQ_SUB tokens are indented correctly", { + expect_warning(test_collection("indention_operators", + "logical_special", + transformer = style_text), NA) +}) + +test_that("dollar is indented and spaced correctl", { + expect_warning(test_collection("indention_operators", + "dollar", + transformer = style_text), NA) +}) + test_that("overall", { expect_warning(test_collection("indention_operators",