Debian Codegraph @

tests/testthat/test-fs_perms.R

raw
1 if (!is_windows()) {
2 describe("as_fs_perms (POSIX)", {
3 it("coerces integers", {
4 expect_equal(as_fs_perms(420L), new_fs_perms(420L))
5 expect_equal(as_fs_perms(NA_integer_), new_fs_perms(NA_integer_))
6
7 expect_equal(as_fs_perms(c(511L, 420L)), new_fs_perms(c(511L, 420L)))
8 })
9
10 it("coerces doubles to integers", {
11 expect_equal(as_fs_perms(420), new_fs_perms(420L))
12 expect_equal(as_fs_perms(NA_real_), new_fs_perms(NA_integer_))
13 expect_equal(as_fs_perms(c(511, 420)), new_fs_perms(c(511L, 420L)))
14 })
15 it("coerces octmode", {
16 expect_equal(as_fs_perms(as.octmode("777")), new_fs_perms(511L))
17 expect_equal(
18 as_fs_perms(as.octmode(c("644", "777"))),
19 new_fs_perms(c(420L, 511L))
20 )
21 })
22 it("coerces characters in octal notation", {
23 expect_equal(as_fs_perms("777"), new_fs_perms(511L))
24 expect_equal(as_fs_perms(c("644", "777")), new_fs_perms(c(420L, 511L)))
25
26 expect_snapshot(
27 error = TRUE,
28 as_fs_perms("777777"),
29 transform = transform_error
30 )
31 })
32 it("coerces characters in symbolic notation", {
33 expect_equal(as_fs_perms("a+rwx"), new_fs_perms(511L))
34 expect_equal(
35 as_fs_perms(c("u+rw,go+r", "a+rwx")),
36 new_fs_perms(c(420L, 511L))
37 )
38 })
39 it("coerces characters in symbolic notation", {
40 expect_equal(as_fs_perms("rw-r--r--"), new_fs_perms(420L))
41 expect_equal(
42 as_fs_perms(c("rw-r--r--", "rwxrwxrwx")),
43 new_fs_perms(c(420L, 511L))
44 )
45 })
46 it("preserves the class with both subset and subset2", {
47 expect_s3_class(as_fs_perms("777")[1], "fs_perms")
48 expect_s3_class(as_fs_perms("777")[[1]], "fs_perms")
49 })
50 })
51 } else {
52 describe("as_fs_perms (Windows)", {
53 skip_on_os(c("mac", "linux", "solaris"))
54 it("coerces integers", {
55 expect_equal(as_fs_perms(384L), new_fs_perms(384L))
56 expect_equal(as_fs_perms(NA_integer_), new_fs_perms(NA_integer_))
57
58 expect_equal(as_fs_perms(c(256L, 384L)), new_fs_perms(c(256L, 384L)))
59 })
60
61 it("coerces doubles to integers", {
62 expect_equal(as_fs_perms(384), new_fs_perms(384L))
63 expect_equal(as_fs_perms(NA_real_), new_fs_perms(NA_integer_))
64 expect_equal(as_fs_perms(c(256, 384)), new_fs_perms(c(256L, 384L)))
65 })
66 it("coerces octmode", {
67 expect_equal(as_fs_perms(as.octmode("600")), new_fs_perms(384L))
68 expect_equal(
69 as_fs_perms(as.octmode(c("600", "700"))),
70 new_fs_perms(c(384L, 448L))
71 )
72 expect_equal(
73 as_fs_perms(as.octmode(c("666", "777"))),
74 new_fs_perms(c(438L, 511L))
75 )
76 })
77 it("coerces characters in octal notation", {
78 expect_equal(as_fs_perms("700"), new_fs_perms(448L))
79 expect_equal(as_fs_perms(c("644", "777")), new_fs_perms(c(384L, 448L)))
80
81 #expect_snapshot(error = TRUE, as_fs_perms("777777"))
82 })
83 it("ignores group and other octmode groups", {
84 expect_equal(as_fs_perms(c("666", "777")), new_fs_perms(c(384L, 448L)))
85 })
86 it("coerces characters in symbolic notation", {
87 expect_equal(as_fs_perms("a+rw"), new_fs_perms(384L))
88 expect_equal(as_fs_perms(c("u+rw", "a+rwx")), new_fs_perms(c(384L, 448L)))
89 })
90 it("coerces characters in symbolic notation", {
91 expect_equal(as_fs_perms("rw-"), new_fs_perms(384L))
92 expect_equal(as_fs_perms(c("rw-", "rwx")), new_fs_perms(c(384L, 448L)))
93 })
94 it("returns 'rwx' on windows", {
95 expect_equal(as.character(as_fs_perms("777")), "rwx")
96 })
97 })
98 }
99
100 test_that("common type of double and fs_perms is fs_perms", {
101 expect_identical(
102 vctrs::vec_ptype2(double(), fs_perms()),
103 fs_perms()[0]
104 )
105 expect_identical(
106 vctrs::vec_ptype2(fs_perms(), double()),
107 fs_perms()[0]
108 )
109 })
110
111 test_that("fs_perms and double are coercible", {
112 expect_identical(
113 vctrs::vec_cast(1, fs_perms()),
114 fs_perms(1)
115 )
116 expect_identical(
117 vctrs::vec_cast(fs_perms(1), double()),
118 1L
119 )
120 expect_identical(
121 vctrs::vec_cast(fs_perms(1), fs_perms()),
122 fs_perms(1)
123 )
124 })
125
126 test_that("can concatenate fs_perms", {
127 expect_identical(
128 vctrs::vec_c(fs_perms(1), fs_perms(2)),
129 as_fs_perms(c(1, 2))
130 )
131 })
132
133 test_that("common type of integer and fs_perms is fs_perms", {
134 expect_identical(
135 vctrs::vec_ptype2(integer(), fs_perms()),
136 fs_perms()[0]
137 )
138 expect_identical(
139 vctrs::vec_ptype2(fs_perms(), integer()),
140 fs_perms()[0]
141 )
142 })
143
144 test_that("fs_perms and integer are coercible", {
145 expect_identical(
146 vctrs::vec_cast(1L, fs_perms()),
147 fs_perms(1L)
148 )
149 expect_identical(
150 vctrs::vec_cast(fs_perms(1L), integer()),
151 1L
152 )
153 })
154
155 test_that("common type of character and fs_perms is fs_perms", {
156 expect_identical(
157 vctrs::vec_ptype2(character(), fs_perms()),
158 fs_perms()[0]
159 )
160 expect_identical(
161 vctrs::vec_ptype2(fs_perms(), character()),
162 fs_perms()[0]
163 )
164 })
165
166 test_that("fs_perms and character are coercible", {
167 expect_identical(
168 vctrs::vec_cast("777", fs_perms()),
169 fs_perms("777")
170 )
171
172 # This test only return rwx on Windows due to the less fine grained
173 # permissions, so we skip it
174 skip_on_os("windows")
175 expect_identical(
176 vctrs::vec_cast(fs_perms("777"), character()),
177 "rwxrwxrwx"
178 )
179 })