-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathon_disk_test.go
More file actions
79 lines (72 loc) · 1.75 KB
/
Copy pathon_disk_test.go
File metadata and controls
79 lines (72 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package pathlib_test
import (
"strings"
"testing"
"github.com/skalt/pathlib.go"
)
func TestOnDisk_ensemble(t *testing.T) {
dir := expect(pathlib.TempDir().
Join("test/on-disk/ensemble.dir").
AsDir().
MakeAll(0777, 0777))
assertEq := func(a, b any) {
if a != b {
t.Fatalf("- %#v\n+ %#v\n", a, b)
}
}
info := expect(dir.Stat())
assertEq(info.Parent(), pathlib.TempDir().Join("test/on-disk").AsDir())
assertEq(info.BaseName(), "ensemble.dir")
assertEq(info.Ext(), ".dir")
assertEq(info.IsAbsolute(), true)
assertEq(info.IsLocal(), false)
assertEq(info.Join("foo"), pathlib.TempDir().Join("/test/on-disk/ensemble.dir/foo"))
assertEq(
strings.Join(info.Parts(), "\n"),
strings.Join(
[]string{
"/",
pathlib.TempDir().BaseName(),
"test",
"on-disk",
"ensemble.dir",
},
"\n",
),
)
}
func TestOnDisk_Transformer(t *testing.T) {
onDisk := expect(pathlib.Dir(t.TempDir()).Stat())
if !onDisk.IsAbsolute() {
t.Fail()
}
if expect(onDisk.Abs()) != onDisk.Path() {
t.Fail()
}
if expect(onDisk.ExpandUser()) != onDisk.Path() {
t.Fail()
}
if !onDisk.Eq(onDisk.Clean()) {
t.Fatal(expect(onDisk.Abs()), expect(onDisk.Clean().Abs()))
}
if !strings.HasPrefix(onDisk.String(), "/") {
t.Fail()
}
if expect(onDisk.Rel(onDisk.Parent())).String() != onDisk.BaseName() {
t.Fail()
}
if _, err := onDisk.Localize(); err == nil { // localize fails when paths start with a /
t.Fail()
}
}
func TestOnDisk_manipulator(t *testing.T) {
temp := pathlib.Dir(t.TempDir())
dir := expect(temp.Join("foo").AsDir().Make(0777))
onDisk := expect(dir.Stat())
if err := onDisk.Chmod(0755); err != nil {
t.Fatal(err)
}
renamed := expect(onDisk.Rename(temp.Join("bar")))
onDisk = expect(renamed.Stat())
enforce(onDisk.Remove())
}