1
2
3
4
5 package objabi
6
7 import (
8 "path/filepath"
9 "runtime"
10 "testing"
11 )
12
13
14
15
16 func drive() string {
17 if runtime.GOOS == "windows" {
18 return "c:"
19 }
20 return ""
21 }
22
23 var absFileTests = []struct {
24 dir string
25 file string
26 rewrites string
27 abs string
28 }{
29 {"/d", "f", "", "/d/f"},
30 {"/d", drive() + "/f", "", drive() + "/f"},
31 {"/d", "f/g", "", "/d/f/g"},
32 {"/d", drive() + "/f/g", "", drive() + "/f/g"},
33
34 {"/d", "f", "/d/f", "??"},
35 {"/d", "f/g", "/d/f", "g"},
36 {"/d", "f/g", "/d/f=>h", "h/g"},
37 {"/d", "f/g", "/d/f=>/h", "/h/g"},
38 {"/d", "f/g", "/d/f=>/h;/d/e=>/i", "/h/g"},
39 {"/d", "e/f", "/d/f=>/h;/d/e=>/i", "/i/f"},
40 }
41
42 func TestAbsFile(t *testing.T) {
43 for _, tt := range absFileTests {
44 abs := filepath.FromSlash(AbsFile(filepath.FromSlash(tt.dir), filepath.FromSlash(tt.file), tt.rewrites))
45 want := filepath.FromSlash(tt.abs)
46 if abs != want {
47 t.Errorf("AbsFile(%q, %q, %q) = %q, want %q", tt.dir, tt.file, tt.rewrites, abs, want)
48 }
49 }
50 }
51
View as plain text