9sh

9P shell
Log | Files | Refs

path_test.go (779B)


      1 package main
      2 
      3 import (
      4 	"testing"
      5 )
      6 
      7 func TestAbsPath(t *testing.T) {
      8 	tests := []struct {
      9 		cwd, pth, want string
     10 	}{
     11 		{"/a", "../../", "."},
     12 		{"/a", "b/../c", "a/c"},
     13 		{"/", ".", "."},
     14 		{"/", "", "."},
     15 		{"", "", "."},
     16 		{"", "/a/b/c", "a/b/c"},
     17 	}
     18 	for _, test := range tests {
     19 		got := absPath(test.cwd, test.pth)
     20 		if got != test.want {
     21 			t.Errorf("absPath(%q, %q) = %q, want: %q",
     22 				test.cwd, test.pth, got, test.want)
     23 		}
     24 	}
     25 }
     26 
     27 func TestRelPath(t *testing.T) {
     28 	tests := []struct {
     29 		cwd, pth, want string
     30 	}{
     31 		{"/a", "/a/b/c", "b/c"},
     32 		{"/a", "/c", "c"},
     33 		{"/", ".", "."},
     34 	}
     35 	for _, test := range tests {
     36 		got := relPath(test.cwd, test.pth)
     37 		if got != test.want {
     38 			t.Errorf("relPath(%q, %q) = %q, want: %q",
     39 				test.cwd, test.pth, got, test.want)
     40 		}
     41 	}
     42 }