mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
- Add changelog entry for v0.19.11 (preserve_tilde_on_save, backups gitignore) - Document preserve_tilde_on_save in configuration reference, cross-machine sync, FAQ - Fix TestFoldHomePath/unrelated-abs: use /opt/unrelated/foo instead of /tmp/foo (CI sets HOME=/tmp) - Add iFwu to README contributors
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestFoldHomePath(t *testing.T) {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil || home == "" {
|
|
t.Skip("UserHomeDir unavailable")
|
|
}
|
|
sep := string(filepath.Separator)
|
|
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"empty", "", ""},
|
|
{"already-tilde", "~/foo", "~/foo"},
|
|
{"exact-home", home, "~"},
|
|
{"home-child", home + sep + "foo", "~" + sep + "foo"},
|
|
{"home-deep", home + sep + ".config" + sep + "skillshare", "~" + sep + ".config" + sep + "skillshare"},
|
|
{"sibling-not-home", home + "_other" + sep + "foo", home + "_other" + sep + "foo"},
|
|
{"unrelated-abs", "/opt/unrelated/foo", "/opt/unrelated/foo"},
|
|
{"relative", "foo/bar", "foo/bar"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := FoldHomePath(tt.in)
|
|
if got != tt.want {
|
|
t.Errorf("FoldHomePath(%q) = %q, want %q", tt.in, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFoldHomePath_WindowsCaseInsensitive(t *testing.T) {
|
|
if runtime.GOOS != "windows" {
|
|
t.Skip("Windows-only case-fold behavior")
|
|
}
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
t.Skip("UserHomeDir unavailable")
|
|
}
|
|
// Pretend the path comes back with different casing (common on Windows).
|
|
mixed := strings.ToLower(home) + string(filepath.Separator) + "Foo"
|
|
got := FoldHomePath(mixed)
|
|
if !strings.HasPrefix(got, "~") {
|
|
t.Errorf("FoldHomePath(%q) = %q, expected fold under mixed case", mixed, got)
|
|
}
|
|
}
|