Split into packages only manually tested
This commit is contained in:
71
filetree/path_test.go
Executable file
71
filetree/path_test.go
Executable file
@@ -0,0 +1,71 @@
|
||||
package filetree
|
||||
|
||||
import (
|
||||
"local/notes-server/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPathIs(t *testing.T) {
|
||||
p := Path{Local: "/dev/null"}
|
||||
if ok := p.IsDir(); ok {
|
||||
t.Fatal(ok, p)
|
||||
}
|
||||
|
||||
if ok := p.IsFile(); !ok {
|
||||
t.Fatal(ok, p)
|
||||
}
|
||||
|
||||
p = Path{Local: "/tmp"}
|
||||
if ok := p.IsDir(); !ok {
|
||||
t.Fatal(ok, p)
|
||||
}
|
||||
|
||||
if ok := p.IsFile(); ok {
|
||||
t.Fatal(ok, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewPathFromLocal(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
root string
|
||||
href string
|
||||
local string
|
||||
}{
|
||||
{
|
||||
in: "/wiki/b/a.md",
|
||||
root: "/wiki",
|
||||
href: "/notes/b/a.md",
|
||||
local: "/wiki/b/a.md",
|
||||
},
|
||||
{
|
||||
in: "/wiki/a.md",
|
||||
root: "/wiki",
|
||||
href: "/notes/a.md",
|
||||
local: "/wiki/a.md",
|
||||
},
|
||||
{
|
||||
in: "/b/a.md",
|
||||
root: "/",
|
||||
href: "/notes/b/a.md",
|
||||
local: "/b/a.md",
|
||||
},
|
||||
{
|
||||
in: "/a.md",
|
||||
root: "/",
|
||||
href: "/notes/a.md",
|
||||
local: "/a.md",
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
config.Root = c.root
|
||||
p := NewPathFromLocal(c.in)
|
||||
if p.HREF != c.href {
|
||||
t.Fatal(i, "href", p.HREF, c.href, c, p)
|
||||
}
|
||||
if p.Local != c.local {
|
||||
t.Fatal(i, "local", p.Local, c.local, c, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user