delve/pkg/terminal/terminal_test.go
Derek Parker 4c9a72e486 *: Update import name to github.com/go-delve/delve
The repository is being switched from the personal account
github.com/derekparker/delve to the organization account
github.com/go-delve/delve. This patch updates imports and docs, while
preserving things which should not be changed such as my name in the
CHANGELOG and in TODO comments.
2019-01-04 19:43:13 +01:00

81 lines
2.7 KiB
Go

package terminal
import (
"runtime"
"testing"
"github.com/go-delve/delve/pkg/config"
)
type tRule struct {
from string
to string
}
type tCase struct {
rules []tRule
path string
res string
}
func platformCases() []tCase {
casesUnix := []tCase{
// Should not depend on separator at the end of rule path
{[]tRule{{"/tmp/path", "/new/path2"}}, "/tmp/path/file.go", "/new/path2/file.go"},
{[]tRule{{"/tmp/path/", "/new/path2/"}}, "/tmp/path/file.go", "/new/path2/file.go"},
{[]tRule{{"/tmp/path/", "/new/path2"}}, "/tmp/path/file.go", "/new/path2/file.go"},
{[]tRule{{"/tmp/path", "/new/path2/"}}, "/tmp/path/file.go", "/new/path2/file.go"},
// Should apply only for directory names
{[]tRule{{"/tmp/path", "/new/path2"}}, "/tmp/path-2/file.go", "/tmp/path-2/file.go"},
// First matched rule should be used
{[]tRule{
{"/tmp/path1", "/new/path1"},
{"/tmp/path2", "/new/path2"},
{"/tmp/path2", "/new/path3"}}, "/tmp/path2/file.go", "/new/path2/file.go"},
}
casesLinux := []tCase{
// Should be case-sensitive
{[]tRule{{"/tmp/path", "/new/path2"}}, "/TmP/path/file.go", "/TmP/path/file.go"},
}
casesDarwin := []tCase{
// Can be either case-sensitive or case-insensitive depending on
// filesystem settings, we always treat it as case-sensitive.
{[]tRule{{"/tmp/path", "/new/path2"}}, "/TmP/PaTh/file.go", "/TmP/PaTh/file.go"},
}
casesWindows := []tCase{
// Should not depend on separator at the end of rule path
{[]tRule{{`c:\tmp\path`, `d:\new\path2`}}, `c:\tmp\path\file.go`, `d:\new\path2\file.go`},
{[]tRule{{`c:\tmp\path\`, `d:\new\path2\`}}, `c:\tmp\path\file.go`, `d:\new\path2\file.go`},
{[]tRule{{`c:\tmp\path`, `d:\new\path2\`}}, `c:\tmp\path\file.go`, `d:\new\path2\file.go`},
{[]tRule{{`c:\tmp\path\`, `d:\new\path2`}}, `c:\tmp\path\file.go`, `d:\new\path2\file.go`},
// Should apply only for directory names
{[]tRule{{`c:\tmp\path`, `d:\new\path2`}}, `c:\tmp\path-2\file.go`, `c:\tmp\path-2\file.go`},
// Should be case-insensitive
{[]tRule{{`c:\tmp\path`, `d:\new\path2`}}, `C:\TmP\PaTh\file.go`, `d:\new\path2\file.go`},
}
if runtime.GOOS == "windows" {
return casesWindows
}
if runtime.GOOS == "darwin" {
return append(casesUnix, casesDarwin...)
}
if runtime.GOOS == "linux" {
return append(casesUnix, casesLinux...)
}
return casesUnix
}
func TestSubstitutePath(t *testing.T) {
for _, c := range platformCases() {
var subRules config.SubstitutePathRules
for _, r := range c.rules {
subRules = append(subRules, config.SubstitutePathRule{From: r.from, To: r.to})
}
res := New(nil, &config.Config{SubstitutePath: subRules}).substitutePath(c.path)
if c.res != res {
t.Errorf("terminal.SubstitutePath(%q) => %q, want %q", c.path, res, c.res)
}
}
}