@@ -48,6 +48,43 @@ capture.output(test_that("activated cache brings speedup on style_text() API on
4848}))
4949
5050
51+ test_that(" trailing line breaks are ignored for caching" , {
52+ on.exit(clear_testthat_cache())
53+ clear_testthat_cache()
54+ activate_testthat_cache()
55+
56+ first <- system.time(styler :: style_text(paste0(text , collapse = " \n " )))
57+ second <- system.time(
58+ styler :: style_text(c(paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " ))
59+ )
60+ expect_true(first [" elapsed" ] / 2 > second [" elapsed" ])
61+ # check we only have three different expressions. Top-level, example and fun.
62+ cache_info <- cache_info()
63+ expect_equal(
64+ cache_info $ n ,
65+ 3
66+ )
67+ })
68+
69+ test_that(" trailing line breaks are ignored for caching in one scalar" , {
70+ on.exit(clear_testthat_cache())
71+ clear_testthat_cache()
72+ activate_testthat_cache()
73+
74+ first <- system.time(styler :: style_text(paste0(text , collapse = " \n " )))
75+ second <- system.time(
76+ styler :: style_text(
77+ paste0(paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " , collapse = " " )
78+ ))
79+ expect_true(first [" elapsed" ] / 2 > second [" elapsed" ])
80+ # check we only have three different expressions. Top-level, example and fun.
81+ cache_info <- cache_info()
82+ expect_equal(
83+ cache_info $ n ,
84+ 3
85+ )
86+ })
87+
5188capture.output(test_that(" no speedup when tranformer changes" , {
5289
5390 activate_testthat_cache()
0 commit comments