@@ -17,3 +17,37 @@ test_that("styler can style file", {
17
17
})
18
18
19
19
# style_active_file() must be tested manually.
20
+ test_that(" ..." , {
21
+ before_styling <- utf8 :: read_lines_enc(paste0(base , " /xyzaddin/addin_region-in.R" ))
22
+ reference <- utf8 :: read_lines_enc(paste0(base , " /xyzaddin/addin_region-out.R" ))
23
+ result <- expect_error(
24
+ testthat :: with_mock(
25
+ find_active_context = function () {
26
+ context <- structure(list (
27
+ id = " C533793B" ,
28
+ path = paste0(base , " /xyzaddin/addin_region-in.R" ),
29
+ contents = c(" fjkdsfa 2jy+wj/ 1+1 <?+d" , " " ),
30
+ selection = structure(list (structure(list (range = structure(list (
31
+ start = structure(c(1 , 17 ), .Names = c(" row" , " column" ), class = " document_position" ),
32
+ end = structure(c(1 , 21 ), .Names = c(" row" , " column" ),
33
+ class = " document_position" )), .Names = c(" start" , " end" ),
34
+ class = " document_range" ), text = " 1+1 " ), .Names = c(" range" , " text" ))),
35
+ .Names = " " , class = " document_selection" )),
36
+ .Names = c(" id" , " path" , " contents" , " selection" ), class = " document_context"
37
+ )
38
+ path <- context $ path
39
+ start <- context $ selection [[1 ]]$ range $ start
40
+ end <- context $ selection [[1 ]]$ range $ end
41
+ if (all(start == end )) return ()
42
+ if (end [2 ] == 1 ) {
43
+ end [1 ] <- end [1 ] - 1
44
+ end [2 ] <- 1000000L # because of range constraint in substr()
45
+ }
46
+ list (start = start , end = end , path = path )
47
+ },
48
+ style_active_region()
49
+ ), NA )
50
+ after_styling <- utf8 :: read_lines_enc(paste0(base , " /xyzaddin/addin_region-in.R" ))
51
+ expect_equivalent(after_styling , reference )
52
+ utf8 :: write_lines_enc(before_styling , paste0(base , " /xyzaddin/addin_region-in.R" ))
53
+ })
0 commit comments