Skip to content

Commit 673efad

Browse files
authored
docs: Use single quotes to avoid nested double quotes (#161)
1 parent 84dffb2 commit 673efad

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

R/root.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ has_file <- function(filepath, contents = NULL, n = -1L, fixed = FALSE) {
201201
}))
202202

203203
desc <- paste0(
204-
'contains a file "', filepath, '"',
204+
"contains a file '", filepath, "'",
205205
if (!is.null(contents)) {
206206
paste0(
207207
" with contents ",
208208
if (!fixed) "matching ",
209-
'"', contents, '"',
209+
"'", contents, "'",
210210
if (n >= 0L) paste0(" in the first ", format_lines(n))
211211
)
212212
}
@@ -232,7 +232,7 @@ has_dir <- function(filepath) {
232232
dir.exists(testfile)
233233
}))
234234

235-
desc <- paste0('contains a directory "', filepath, '"')
235+
desc <- paste0("contains a directory '", filepath, "'")
236236

237237
root_criterion(testfun, desc)
238238
}
@@ -273,12 +273,12 @@ has_file_pattern <- function(pattern, contents = NULL, n = -1L, fixed = FALSE) {
273273
}))
274274

275275
desc <- paste0(
276-
'contains a file matching "', pattern, '"',
276+
"contains a file matching '", pattern, "'",
277277
if (!is.null(contents)) {
278278
paste0(
279279
" with contents ",
280280
if (!fixed) "matching ",
281-
'"', contents, '"',
281+
"'", contents, "'",
282282
if (n >= 0L) paste0(" in the first ", format_lines(n))
283283
)
284284
}

tests/testthat/_snaps/root.md

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,87 @@
33
Code
44
format(is_r_package)
55
Output
6-
[1] "Root criterion: contains a file \"DESCRIPTION\" with contents matching \"^Package: \""
6+
[1] "Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '"
77

88
---
99

1010
Code
1111
is_r_package
1212
Output
13-
Root criterion: contains a file "DESCRIPTION" with contents matching "^Package: "
13+
Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '
1414

1515
---
1616

1717
Code
1818
is_vcs_root
1919
Output
2020
Root criterion: one of
21-
- contains a directory ".git"
22-
- contains a file ".git" with contents matching "^gitdir: "
23-
- contains a directory ".svn"
21+
- contains a directory '.git'
22+
- contains a file '.git' with contents matching '^gitdir: '
23+
- contains a directory '.svn'
2424

2525
---
2626

2727
Code
2828
has_file("a", contents = "foo", fixed = TRUE)
2929
Output
30-
Root criterion: contains a file "a" with contents "foo"
30+
Root criterion: contains a file 'a' with contents 'foo'
3131

3232
---
3333

3434
Code
3535
has_file_pattern("a.*b", contents = "foo", fixed = TRUE)
3636
Output
37-
Root criterion: contains a file matching "a.*b" with contents "foo"
37+
Root criterion: contains a file matching 'a.*b' with contents 'foo'
3838

3939
---
4040

4141
Code
4242
criteria
4343
Output
4444
$is_rstudio_project
45-
Root criterion: contains a file matching "[.]Rproj$" with contents matching "^Version: " in the first line
45+
Root criterion: contains a file matching '[.]Rproj$' with contents matching '^Version: ' in the first line
4646
4747
$is_vscode_project
48-
Root criterion: contains a directory ".vscode"
48+
Root criterion: contains a directory '.vscode'
4949
5050
$is_r_package
51-
Root criterion: contains a file "DESCRIPTION" with contents matching "^Package: "
51+
Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '
5252
5353
$is_remake_project
54-
Root criterion: contains a file "remake.yml"
54+
Root criterion: contains a file 'remake.yml'
5555
5656
$is_pkgdown_project
5757
Root criterion: one of
58-
- contains a file "_pkgdown.yml"
59-
- contains a file "_pkgdown.yaml"
60-
- contains a file "pkgdown/_pkgdown.yml"
61-
- contains a file "pkgdown/_pkgdown.yaml"
62-
- contains a file "inst/_pkgdown.yml"
63-
- contains a file "inst/_pkgdown.yaml"
58+
- contains a file '_pkgdown.yml'
59+
- contains a file '_pkgdown.yaml'
60+
- contains a file 'pkgdown/_pkgdown.yml'
61+
- contains a file 'pkgdown/_pkgdown.yaml'
62+
- contains a file 'inst/_pkgdown.yml'
63+
- contains a file 'inst/_pkgdown.yaml'
6464
6565
$is_renv_project
66-
Root criterion: contains a file "renv.lock" with contents matching ""Packages":\s*\{"
66+
Root criterion: contains a file 'renv.lock' with contents matching '"Packages":\s*\{'
6767
6868
$is_projectile_project
69-
Root criterion: contains a file ".projectile"
69+
Root criterion: contains a file '.projectile'
7070
7171
$is_quarto_project
72-
Root criterion: contains a file "_quarto.yml"
72+
Root criterion: contains a file '_quarto.yml'
7373
7474
$is_git_root
7575
Root criterion: one of
76-
- contains a directory ".git"
77-
- contains a file ".git" with contents matching "^gitdir: "
76+
- contains a directory '.git'
77+
- contains a file '.git' with contents matching '^gitdir: '
7878
7979
$is_svn_root
80-
Root criterion: contains a directory ".svn"
80+
Root criterion: contains a directory '.svn'
8181
8282
$is_vcs_root
8383
Root criterion: one of
84-
- contains a directory ".git"
85-
- contains a file ".git" with contents matching "^gitdir: "
86-
- contains a directory ".svn"
84+
- contains a directory '.git'
85+
- contains a file '.git' with contents matching '^gitdir: '
86+
- contains a directory '.svn'
8787
8888
$is_testthat
8989
Root criterion: directory name is "testthat" (also look in subdirectories: `tests/testthat`, `testthat`)
@@ -100,17 +100,17 @@
100100
str(criteria)
101101
Output
102102
List of 13
103-
$ is_rstudio_project : chr "Root criterion: contains a file matching \"[.]Rproj$\" with contents matching \"^Version: \" in the first line"
104-
$ is_vscode_project : chr "Root criterion: contains a directory \".vscode\""
105-
$ is_r_package : chr "Root criterion: contains a file \"DESCRIPTION\" with contents matching \"^Package: \""
106-
$ is_remake_project : chr "Root criterion: contains a file \"remake.yml\""
107-
$ is_pkgdown_project : chr [1:7] "Root criterion: one of" "- contains a file \"_pkgdown.yml\"" "- contains a file \"_pkgdown.yaml\"" "- contains a file \"pkgdown/_pkgdown.yml\"" ...
108-
$ is_renv_project : chr "Root criterion: contains a file \"renv.lock\" with contents matching \"\"Packages\":\\s*\\{\""
109-
$ is_projectile_project: chr "Root criterion: contains a file \".projectile\""
110-
$ is_quarto_project : chr "Root criterion: contains a file \"_quarto.yml\""
111-
$ is_git_root : chr [1:3] "Root criterion: one of" "- contains a directory \".git\"" "- contains a file \".git\" with contents matching \"^gitdir: \""
112-
$ is_svn_root : chr "Root criterion: contains a directory \".svn\""
113-
$ is_vcs_root : chr [1:4] "Root criterion: one of" "- contains a directory \".git\"" "- contains a file \".git\" with contents matching \"^gitdir: \"" "- contains a directory \".svn\""
103+
$ is_rstudio_project : chr "Root criterion: contains a file matching '[.]Rproj$' with contents matching '^Version: ' in the first line"
104+
$ is_vscode_project : chr "Root criterion: contains a directory '.vscode'"
105+
$ is_r_package : chr "Root criterion: contains a file 'DESCRIPTION' with contents matching '^Package: '"
106+
$ is_remake_project : chr "Root criterion: contains a file 'remake.yml'"
107+
$ is_pkgdown_project : chr [1:7] "Root criterion: one of" "- contains a file '_pkgdown.yml'" "- contains a file '_pkgdown.yaml'" "- contains a file 'pkgdown/_pkgdown.yml'" ...
108+
$ is_renv_project : chr "Root criterion: contains a file 'renv.lock' with contents matching '\"Packages\":\\s*\\{'"
109+
$ is_projectile_project: chr "Root criterion: contains a file '.projectile'"
110+
$ is_quarto_project : chr "Root criterion: contains a file '_quarto.yml'"
111+
$ is_git_root : chr [1:3] "Root criterion: one of" "- contains a directory '.git'" "- contains a file '.git' with contents matching '^gitdir: '"
112+
$ is_svn_root : chr "Root criterion: contains a directory '.svn'"
113+
$ is_vcs_root : chr [1:4] "Root criterion: one of" "- contains a directory '.git'" "- contains a file '.git' with contents matching '^gitdir: '" "- contains a directory '.svn'"
114114
$ is_testthat : chr "Root criterion: directory name is \"testthat\" (also look in subdirectories: `tests/testthat`, `testthat`)"
115115
$ from_wd : chr "Root criterion: from current working directory"
116116

@@ -120,6 +120,13 @@
120120
comb_crit
121121
Output
122122
Root criterion: one of
123-
- contains a file "DESCRIPTION" with contents matching "^Package: "
124-
- contains a file matching "[.]Rproj$" with contents matching "^Version: " in the first line
123+
- contains a file 'DESCRIPTION' with contents matching '^Package: '
124+
- contains a file matching '[.]Rproj$' with contents matching '^Version: ' in the first line
125+
126+
# is_renv_project prints regex-friendly-ish text
127+
128+
Code
129+
is_renv_project
130+
Output
131+
Root criterion: contains a file 'renv.lock' with contents matching '"Packages":\s*\{'
125132

tests/testthat/test-root.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,10 @@ test_that("stops if depth reached", {
308308
# Checks that search for root terminates for very deep hierarchies
309309
expect_error(find_root_mocked(""), "Maximum search of [0-9]+ exceeded")
310310
})
311+
312+
# The exact style of quoting here (double inside single as opposed to nested
313+
# double quotes) makes generating the here docs *much less fiddly*.
314+
# See https://github.com/r-lib/here/pull/130
315+
test_that("is_renv_project prints regex-friendly-ish text", {
316+
expect_snapshot(is_renv_project)
317+
})

0 commit comments

Comments
 (0)