package step import "os" import "testing" import "path/filepath" func TestDocumentAbs (test *testing.T) { document := Document { name: "foo/bar.step", } cwd, err := os.Getwd() if err != nil { test.Fatal(err) } path1, err := document.Abs("thing.step") if err != nil { test.Fatal(err) } path2, err := document.Abs("thing/other.step") if err != nil { test.Fatal(err) } path3, err := document.Abs("./thing/other.step") if err != nil { test.Fatal(err) } path4, err := document.Abs("../thing/other.step") if err != nil { test.Fatal(err) } path5, err := document.Abs("/something/thing") if err != nil { test.Fatal(err) } test.Log(path1) if path1 != filepath.Join(cwd, "thing.step") { test.Fatal("incorrect path") } test.Log(path2) if path2 != filepath.Join(cwd, "thing/other.step") { test.Fatal("incorrect path") } test.Log(path3) if path3 != filepath.Join(cwd, "foo/thing/other.step") { test.Fatal("incorrect path") } test.Log(path4) if path4 != filepath.Join(cwd, "thing/other.step") { test.Fatal("incorrect path") } test.Log(path5) if path5 != "/something/thing" { test.Fatal("incorrect path") } } func TestDocumentRel (test *testing.T) { document := Document { name: "foo/bar.step", } path1, err := document.Rel("thing.step") if err != nil { test.Fatal(err) } path2, err := document.Rel("thing/other.step") if err != nil { test.Fatal(err) } path3, err := document.Rel("./thing/other.step") if err != nil { test.Fatal(err) } path4, err := document.Rel("../thing/other.step") if err != nil { test.Fatal(err) } path5, err := document.Rel("/something/thing") if err != nil { test.Fatal(err) } test.Log(path1) if path1 != filepath.Join("thing.step") { test.Fatal("incorrect path") } test.Log(path2) if path2 != filepath.Join("thing/other.step") { test.Fatal("incorrect path") } test.Log(path3) if path3 != filepath.Join("foo/thing/other.step") { test.Fatal("incorrect path") } test.Log(path4) if path4 != filepath.Join("thing/other.step") { test.Fatal("incorrect path") } test.Log(path5) if path5 == "/something/thing" { test.Fatal("incorrect path") } }