Split into packages only manually tested

This commit is contained in:
Bel LaPointe
2019-11-09 18:51:03 -07:00
parent 0d497f4fa8
commit 60dc6bc876
48 changed files with 530 additions and 125 deletions

71
filetree/path_test.go Executable file
View 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)
}
}
}