@@ -24,7 +24,6 @@ text <- c(
2424 rep(10 )
2525
2626capture.output(test_that(" activated cache brings speedup on style_text() API on character vector" , {
27-
2827 activate_testthat_cache()
2928 on.exit(clear_testthat_cache())
3029 clear_testthat_cache()
@@ -36,7 +35,6 @@ capture.output(test_that("activated cache brings speedup on style_text() API on
3635}))
3736
3837capture.output(test_that(" activated cache brings speedup on style_text() API on character scalar" , {
39-
4038 activate_testthat_cache()
4139 on.exit(clear_testthat_cache())
4240 clear_testthat_cache()
@@ -75,7 +73,8 @@ test_that("trailing line breaks are ignored for caching in one scalar", {
7573 second <- system.time(
7674 styler :: style_text(
7775 paste0(paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " , collapse = " " )
78- ))
76+ )
77+ )
7978 expect_true(first [" elapsed" ] / 2 > second [" elapsed" ])
8079 # check we only have three different expressions. Top-level, example and fun.
8180 cache_info <- cache_info()
@@ -86,7 +85,6 @@ test_that("trailing line breaks are ignored for caching in one scalar", {
8685})
8786
8887capture.output(test_that(" no speedup when tranformer changes" , {
89-
9088 activate_testthat_cache()
9189 on.exit(clear_testthat_cache())
9290 clear_testthat_cache()
@@ -112,11 +110,11 @@ capture.output(
112110 first <- system.time(styler :: style_text(text ))
113111 second <- system.time(styler :: style_text(paste0(text , collapse = " \n " )))
114112 expect_true(first [" elapsed" ] / 2 > second [" elapsed" ])
115- }))
113+ })
114+ )
116115
117116
118117capture.output(test_that(" unactivated cache does not bring speedup" , {
119-
120118 on.exit(clear_testthat_cache())
121119 clear_testthat_cache()
122120 cache_deactivate()
@@ -127,7 +125,6 @@ capture.output(test_that("unactivated cache does not bring speedup", {
127125
128126
129127capture.output(test_that(" avoid deleting comments #584 (see commit messages)" , {
130-
131128 on.exit(clear_testthat_cache())
132129 clear_testthat_cache()
133130 activate_testthat_cache()
@@ -136,7 +133,7 @@ capture.output(test_that("avoid deleting comments #584 (see commit messages)", {
136133 " # Comment" ,
137134 " # another" ,
138135 " NULL"
139- )
136+ )
140137 style_text(text )
141138 text2 <- c(
142139 " 1 + 1" ,
@@ -152,7 +149,6 @@ capture.output(test_that("avoid deleting comments #584 (see commit messages)", {
152149
153150
154151capture.output(test_that(" avoid removing roxygen mask (see commit messages in #584)" , {
155-
156152 on.exit(clear_testthat_cache())
157153 clear_testthat_cache()
158154 activate_testthat_cache()
@@ -179,3 +175,26 @@ capture.output(test_that("avoid removing roxygen mask (see commit messages in #5
179175 text2
180176 )
181177}))
178+
179+
180+ capture.output(test_that(" partial caching of multiple expressions on one line works" , {
181+ on.exit(clear_testthat_cache())
182+ clear_testthat_cache()
183+ activate_testthat_cache()
184+ text <- " 1"
185+ style_text(text )
186+ text2 <- " 1 # comment"
187+ styled <- style_text(text2 )
188+ expect_equal(
189+ as.character(styled ),
190+ text2
191+ )
192+
193+ style_text(" mtcars" )
194+ style_text(c(" mtcars %>%" , " f()" ))
195+ final_text <- c(" mtcars %>%" , " f() #" )
196+ expect_equal(
197+ as.character(style_text(final_text )),
198+ final_text
199+ )
200+ }))
0 commit comments