| 1 |
test_that("examples", { |
| 2 |
path <- fs::path("some", "simple", "path", "to", "a", "file.txt") |
| 3 |
expect_equal( |
| 4 |
path_select_components(path, 1:3), |
| 5 |
path("some", "simple", "path") |
| 6 |
) |
| 7 |
expect_equal( |
| 8 |
path_select_components(path, 1:3, "end"), |
| 9 |
path("to", "a", "file.txt") |
| 10 |
) |
| 11 |
expect_equal( |
| 12 |
path_select_components(path, -1, "end"), |
| 13 |
fs::path("some", "simple", "path", "to", "a") |
| 14 |
) |
| 15 |
expect_equal( |
| 16 |
path_select_components(path, 6), |
| 17 |
path("file.txt") |
| 18 |
) |
| 19 |
}) |
| 20 |
|
| 21 |
test_that("vectorized", { |
| 22 |
path <- c( |
| 23 |
fs::path("some", "simple", "path", "to", "a", "file.txt"), |
| 24 |
fs::path("another", "path", "to", "file2.txt") |
| 25 |
) |
| 26 |
|
| 27 |
expect_snapshot({ |
| 28 |
path_select_components(path, 1:3) |
| 29 |
path_select_components(path, 1:3, "end") |
| 30 |
path_select_components(path, integer()) |
| 31 |
unclass(path_select_components(path, integer())) |
| 32 |
|
| 33 |
path_select_components(fs_path(character()), 1:3) |
| 34 |
path_select_components(fs_path(character()), 1:3, "end") |
| 35 |
class(path_select_components(fs_path(character()), 1:3)) |
| 36 |
class(path_select_components(fs_path(character()), 1:3, "end")) |
| 37 |
}) |
| 38 |
}) |