File: test_getRelativePath.R

package info (click to toggle)
r-cran-bbmisc 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,256 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (21 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
context("getRelativePath")

test_that("getRelativePath", {
  base = tempfile("")
  a = file.path(base, "foo")
  b = file.path(base, "bar")
  c = file.path(base, "bar", "foobar")
  lapply(c(a, b, c), dir.create, recursive = TRUE)

  expect_equal(getRelativePath(a, from = base), "foo")
  expect_equal(getRelativePath(b, from = base), "bar")
  expect_equal(getRelativePath(base, from = a), "..")
  expect_equal(getRelativePath(base, from = b), "..")
  expect_equal(getRelativePath(a, from = b), file.path("..", "foo"))
  expect_equal(getRelativePath(b, from = a), file.path("..", "bar"))
  expect_equal(getRelativePath(base, from = c), file.path("..", ".."))
  expect_equal(getRelativePath(c, from = base), file.path("bar", "foobar"))
  expect_equal(getRelativePath(c, from = a), file.path("..", "bar", "foobar"))
  if (!isWindows())
    expect_equal(getRelativePath("/", from = a), do.call(file.path, as.list(rep("..", length(splitPath(a)$path)))))
})