@KoderKow Looks like a very useful set of utility functions!
My advice to increase your code coverage is to separate the ability of your function to convert file paths from its ability to read from the clipboard. This will make it easier to write automated tests specifically for the feature added by your function.
For example, you could modify back_to_forward() to take an argument text:
back_to_forward <- function(text = clipr::read_clip(), render = TRUE) {
if (stringr::str_detect(text, "\\\\")) {
text <- gsub(
pattern = "\\\\",
replacement = "/",
x = text
)
}
if (render) {
rstudioapi::insertText(text)
} else {
text
}
}
The default behavior will be exactly the same, i.e. reading from the clipboard. But now your tests can bypass the requirement of reading from the clipboard by directly passing in a character string. Then you could add these new tests:
test_that("back slash", {
expect_match(back_to_forward("sample\\file\\path", render = FALSE),
"sample/file/path")
})
test_that("forward slash (just paste it!)", {
expect_match(back_to_forward("sample/file/path", render = FALSE),
"sample/file/path")
})
On your local machine, you can run all the tests. But on Travis, the above tests could still run, which would cover most of the lines of the function.