1
- context(" absolute_path_linter" )
2
-
3
1
test_that(" unquote" , {
4
2
f <- lintr ::: unquote
5
3
expect_equal(f(character ()), character ())
6
4
expect_equal(f(" foo" ), " foo" )
7
5
expect_equal(
8
- f(c(" 'f" , " \" f'" , " \" f\" " ), q = " \" " ),
9
- c(" 'f" , " \" f'" , " f" ))
6
+ f(c(" 'f" , " \" f'" , " \" f\" " ), q = " \" " ),
7
+ c(" 'f" , " \" f'" , " f" ))
10
8
expect_equal(
11
- f(c(" \" f\" " , " 'f'" , " `f`" , " `'f'`" ), q = " '" ),
9
+ f(c(" \" f\" " , " 'f'" , " `f`" , " `'f'`" ), q = " '" ),
12
10
c(" \" f\" " , " f" , " `f`" , " `'f'`" ))
13
- expect_equal(f(" `a\\ `b`" , q = c(" `" )), " a`b" )
11
+ expect_equal(f(" `a\\ `b`" , q = c(" `" )), " a`b" )
14
12
x <- c(" \" x\" " , " \"\\ n\" " , " \"\\\\\" " , " \"\\\\ y\" " , " \"\\ ny\" " , " \"\\\\ ny\" " , " \"\\\\\\ ny\" " ,
15
13
" \"\\\\\\\\ ny\" " , " \" '\" " , " \"\\\"\" " , " \" `\" " )
16
14
y <- c(" x" , " \n " , " \\ " , " \\ y" , " \n y" , " \\ ny" , " \\\n y" , " \\\\ ny" , " '" , " \" " , " `" )
17
- expect_equal(f(x , q = " \" " ), y )
15
+ expect_equal(f(x , q = " \" " ), y )
18
16
})
19
17
20
18
test_that(" unescape" , {
@@ -33,24 +31,24 @@ test_that("is_root_path", {
33
31
y <- logical ()
34
32
expect_equal(f(x ), y )
35
33
36
- x <- c( " " , " foo" , " http://rseek.org/" , " ./" , " /" , " /foo" , " '/'" )
37
- y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
34
+ x <- c(" " , " foo" , " http://rseek.org/" , " ./" , " /" , " /foo" , " '/'" )
35
+ y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
38
36
expect_equal(f(x ), y )
39
37
40
- x <- c( " /" , " //" )
38
+ x <- c(" /" , " //" )
41
39
y <- c(TRUE , FALSE )
42
40
expect_equal(f(x ), y )
43
41
44
- x <- c( " ~" , " ~/" , " ~//" , " ~bob2" , " ~foo_bar/" )
45
- y <- c(TRUE , TRUE , TRUE , TRUE , TRUE )
42
+ x <- c(" ~" , " ~/" , " ~//" , " ~bob2" , " ~foo_bar/" )
43
+ y <- c(TRUE , TRUE , TRUE , TRUE , TRUE )
46
44
expect_equal(f(x ), y )
47
45
48
46
x <- c(" c:" , " C:\\ " , " D:/" , " C:\\\\ " , " D://" )
49
- y <- c(TRUE , TRUE , TRUE , FALSE , FALSE )
47
+ y <- c(TRUE , TRUE , TRUE , FALSE , FALSE )
50
48
expect_equal(f(x ), y )
51
49
52
50
x <- c(" \\\\ " , " \\\\ localhost" , " \\\\ localhost\\ " )
53
- y <- c( TRUE , TRUE , TRUE )
51
+ y <- c(TRUE , TRUE , TRUE )
54
52
expect_equal(f(x ), y )
55
53
})
56
54
@@ -62,20 +60,20 @@ test_that("is_absolute_path", {
62
60
y <- logical ()
63
61
expect_equal(f(x ), y )
64
62
65
- x <- c( " /" , " //" , " /foo" , " /foo/" )
66
- y <- c(TRUE , FALSE , TRUE , TRUE )
63
+ x <- c(" /" , " //" , " /foo" , " /foo/" )
64
+ y <- c(TRUE , FALSE , TRUE , TRUE )
67
65
expect_equal(f(x ), y )
68
66
69
- x <- c( " ~" , " ~/foo" , " ~/foo/" , " ~'" ) # nolint
70
- y <- c(TRUE , TRUE , TRUE , FALSE )
67
+ x <- c(" ~" , " ~/foo" , " ~/foo/" , " ~'" )
68
+ y <- c(TRUE , TRUE , TRUE , FALSE )
71
69
expect_equal(f(x ), y )
72
70
73
- x <- c(" c:" , " C:\\ foo\\ " , " C:/foo/" ) # nolint
74
- y <- c(TRUE , TRUE , TRUE )
71
+ x <- c(" c:" , " C:\\ foo\\ " , " C:/foo/" )
72
+ y <- c(TRUE , TRUE , TRUE )
75
73
expect_equal(f(x ), y )
76
74
77
- x <- c(" \\\\ " , " \\\\ localhost" , " \\\\ localhost\\ c$" , " \\\\ localhost\\ c$\\ foo" ) # nolint
78
- y <- c( TRUE , TRUE , TRUE , TRUE )
75
+ x <- c(" \\\\ " , " \\\\ localhost" , " \\\\ localhost\\ c$" , " \\\\ localhost\\ c$\\ foo" )
76
+ y <- c(TRUE , TRUE , TRUE , TRUE )
79
77
expect_equal(f(x ), y )
80
78
})
81
79
@@ -87,16 +85,16 @@ test_that("is_relative_path", {
87
85
y <- logical ()
88
86
expect_equal(f(x ), y )
89
87
90
- x <- c( " /" , " c:\\ " , " ~/" , " foo" , " http://rseek.org/" , " './'" )
91
- y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
88
+ x <- c(" /" , " c:\\ " , " ~/" , " foo" , " http://rseek.org/" , " './'" )
89
+ y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
92
90
expect_equal(f(x ), y )
93
91
94
- x <- c(" /foo" , " foo/" , " foo/bar" , " foo//bar" , " ./foo" , " ../foo" ) # nolint
95
- y <- c( FALSE , TRUE , TRUE , TRUE , TRUE , TRUE )
92
+ x <- c(" /foo" , " foo/" , " foo/bar" , " foo//bar" , " ./foo" , " ../foo" )
93
+ y <- c(FALSE , TRUE , TRUE , TRUE , TRUE , TRUE )
96
94
expect_equal(f(x ), y )
97
95
98
- x <- c(" \\\\ " , " \\ foo" , " foo\\ " , " foo\\ bar" , " .\\ foo" , " ..\\ foo" , " ." , " .." , " ../" ) # nolint
99
- y <- c( FALSE , FALSE , TRUE , TRUE , TRUE , TRUE , TRUE , TRUE , TRUE )
96
+ x <- c(" \\\\ " , " \\ foo" , " foo\\ " , " foo\\ bar" , " .\\ foo" , " ..\\ foo" , " ." , " .." , " ../" )
97
+ y <- c(FALSE , FALSE , TRUE , TRUE , TRUE , TRUE , TRUE , TRUE , TRUE )
100
98
expect_equal(f(x ), y )
101
99
})
102
100
@@ -108,12 +106,12 @@ test_that("is_path", {
108
106
y <- logical ()
109
107
expect_equal(f(x ), y )
110
108
111
- x <- c( " " , " foo" , " http://rseek.org/" , " foo\n bar" , " 'foo/bar'" , " '/'" )
112
- y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
109
+ x <- c(" " , " foo" , " http://rseek.org/" , " foo\n bar" , " 'foo/bar'" , " '/'" )
110
+ y <- c(FALSE , FALSE , FALSE , FALSE , FALSE , FALSE )
113
111
expect_equal(f(x ), y )
114
112
115
- x <- c(" c:" , " .." , " foo/bar" , " foo\\ bar" , " ~" , " \\\\ localhost" ) # nolint
116
- y <- c(TRUE , TRUE , TRUE , TRUE , TRUE , TRUE )
113
+ x <- c(" c:" , " .." , " foo/bar" , " foo\\ bar" , " ~" , " \\\\ localhost" )
114
+ y <- c(TRUE , TRUE , TRUE , TRUE , TRUE , TRUE )
117
115
expect_equal(f(x ), y )
118
116
})
119
117
@@ -125,21 +123,21 @@ test_that("is_valid_path", {
125
123
y <- logical ()
126
124
expect_equal(f(x ), y )
127
125
128
- x <- c(" C:/asdf" , " C:/asd*f" , " a\\ s:df" , " a\\\n sdf" ) # nolint
129
- y <- c( TRUE , FALSE , FALSE , FALSE )
126
+ x <- c(" C:/asdf" , " C:/asd*f" , " a\\ s:df" , " a\\\n sdf" )
127
+ y <- c(TRUE , FALSE , FALSE , FALSE )
130
128
expect_equal(f(x ), y )
131
129
132
- x <- c(" C:/asdf" , " C:/asd*f" , " a\\ s:df" , " a\\\n sdf" ) # nolint
133
- y <- c( TRUE , FALSE , FALSE , FALSE )
134
- expect_equal(f(x , lax = TRUE ), y )
130
+ x <- c(" C:/asdf" , " C:/asd*f" , " a\\ s:df" , " a\\\n sdf" )
131
+ y <- c(TRUE , FALSE , FALSE , FALSE )
132
+ expect_equal(f(x , lax = TRUE ), y )
135
133
136
134
x <- c(" /asdf" , " /asd*f" , " /as:df" , " /a\n sdf" )
137
- y <- c( TRUE , TRUE , TRUE , TRUE )
135
+ y <- c(TRUE , TRUE , TRUE , TRUE )
138
136
expect_equal(f(x ), y )
139
137
140
138
x <- c(" /asdf" , " /asd*f" , " /as:df" , " /a\n sdf" )
141
- y <- c( TRUE , FALSE , FALSE , FALSE )
142
- expect_equal(f(x , lax = TRUE ), y )
139
+ y <- c(TRUE , FALSE , FALSE , FALSE )
140
+ expect_equal(f(x , lax = TRUE ), y )
143
141
})
144
142
145
143
@@ -150,8 +148,8 @@ test_that("is_long_path", {
150
148
y <- logical ()
151
149
expect_equal(f(x ), y )
152
150
153
- x <- c(" foo/" , " /foo" , " n/a" , " Z:\\ foo" , " foo/bar" , " ~/foo" , " ../foo" ) # nolint
154
- y <- c( FALSE , FALSE , FALSE , TRUE , TRUE , TRUE , TRUE )
151
+ x <- c(" foo/" , " /foo" , " n/a" , " Z:\\ foo" , " foo/bar" , " ~/foo" , " ../foo" )
152
+ y <- c(FALSE , FALSE , FALSE , TRUE , TRUE , TRUE , TRUE )
155
153
expect_equal(f(x ), y )
156
154
})
157
155
@@ -160,7 +158,7 @@ test_that("returns the correct linting", {
160
158
msg <- rex :: escape(" Do not use absolute paths." )
161
159
162
160
# strict mode
163
- linter <- absolute_path_linter(lax = FALSE )
161
+ linter <- absolute_path_linter(lax = FALSE )
164
162
non_absolute_path_strings <- c(
165
163
" .." ,
166
164
" ./blah" ,
@@ -191,7 +189,7 @@ test_that("returns the correct linting", {
191
189
}
192
190
193
191
# lax mode: no check for strings that are likely not paths (too short or with special characters)
194
- linter <- absolute_path_linter(lax = TRUE )
192
+ linter <- absolute_path_linter(lax = TRUE )
195
193
unlikely_path_strings <- c(
196
194
" /" ,
197
195
encodeString(" /a\n sdf/bar" ),
0 commit comments