Debian Codegraph @

tests/testthat/test-is.R

raw
1 with_dir_tree(list("foo/bar" = "test"), {
2 skip_on_os("windows")
3 link_create(path_abs("foo/bar"), "foo2")
4 link_create("foo/bar", "relbar")
5 link_create("foo", "relfoo")
6
7 describe("is_file", {
8 it("returns true for files, false for non-files, NA if no object exists", {
9 expect_true(is_file("foo/bar"))
10 expect_false(is_file("foo"))
11 expect_false(is_file("foo2", follow = FALSE))
12 expect_true(is_file("foo2", follow = TRUE))
13 expect_equal(is_file("baz"), c(baz = FALSE))
14 .old_wd <- setwd("foo")
15 expect_false(is_file("../relbar", follow = FALSE))
16 expect_true(is_file("../relbar", follow = TRUE))
17 setwd(.old_wd)
18 })
19 })
20
21 describe("is_dir", {
22 it("returns true for dirs, false for non-dirs, NA if no object exists", {
23 expect_true(is_dir("foo"))
24 expect_false(is_dir("foo/bar"))
25 expect_false(is_dir("foo2", follow = FALSE))
26 expect_false(is_dir("foo2", follow = TRUE))
27 expect_equal(is_dir("baz"), c(baz = FALSE))
28 .old_wd <- setwd("foo")
29 expect_false(is_dir("../relfoo", follow = FALSE))
30 expect_true(is_dir("../relfoo", follow = TRUE))
31 setwd(.old_wd)
32 })
33 })
34
35 describe("is_link", {
36 it("returns true for links, false for non-links, NA if no object exists", {
37 expect_true(is_link("foo2"))
38 expect_false(is_link("foo"))
39 expect_false(is_link("foo/bar"))
40 expect_equal(is_link("baz"), c(baz = FALSE))
41 })
42 })
43
44 describe("is_file_empty", {
45 it("returns true for empty files and false for others", {
46 file_create("blah")
47 expect_true(is_file_empty("blah"))
48 expect_false(is_file_empty("foo/bar"))
49 expect_false(is_file_empty("baz"))
50 })
51 })
52 })
53
54 with_dir_tree(list("foo/bar" = "test"), {
55 describe("is_absolute_path", {
56 it("detects windows absolute paths", {
57 expect_true(is_absolute_path("c:\\"))
58 expect_true(is_absolute_path("c:/"))
59 expect_true(is_absolute_path("P:/"))
60 expect_true(is_absolute_path("P:\\"))
61 expect_true(is_absolute_path("\\\\server\\mountpoint\\"))
62 expect_true(is_absolute_path("\\foo"))
63 expect_true(is_absolute_path("\\foo\\bar"))
64 })
65 it("detects posix absolute paths", {
66 expect_false(is_absolute_path(""))
67 expect_false(is_absolute_path("foo/bar"))
68 expect_false(is_absolute_path("./foo/bar"))
69 expect_false(is_absolute_path("../foo/bar"))
70
71 expect_true(is_absolute_path("/"))
72 expect_true(is_absolute_path("/foo"))
73 expect_true(is_absolute_path("/foo/bar"))
74 expect_true(is_absolute_path("~/foo/bar"))
75 })
76 })
77 })