mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
## New Features
- Tracked repositories: `install --track` to clone team skill repos
- Nested skills: organize in folders, auto-flatten on sync (work/api → work__api)
- Name collision detection: warns when multiple skills share same SKILL.md name
- Auto-pruning: orphaned symlinks cleaned on sync
- Custom naming: `--name` flag for tracked repos
## Changes
- Require target path to exist when adding targets
- Add sync reminder after adding target
- Improve pruning messages (broken vs orphan symlinks)
- Add `{team}:{name}` naming convention recommendation
## Files
- New: update.go, gitignore.go, frontmatter.go
- Updated: sync.go, install.go, uninstall.go, validate.go
- Docs: README.md, SKILL.md
171 lines
4.0 KiB
Go
171 lines
4.0 KiB
Go
package utils
|
|
|
|
import "testing"
|
|
|
|
func TestIsHidden(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected bool
|
|
}{
|
|
{"empty string", "", false},
|
|
{"hidden file", ".hidden", true},
|
|
{"hidden directory", ".git", true},
|
|
{"normal file", "file.txt", false},
|
|
{"normal directory", "src", false},
|
|
{"dot only", ".", true},
|
|
{"double dot", "..", true},
|
|
{"file starting with number", "1file", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := IsHidden(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("IsHidden(%q) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHasTildePrefix(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected bool
|
|
}{
|
|
{"empty string", "", false},
|
|
{"tilde path", "~/Documents", true},
|
|
{"tilde only", "~", true},
|
|
{"absolute path", "/home/user", false},
|
|
{"relative path", "./config", false},
|
|
{"tilde in middle", "/home/~user", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := HasTildePrefix(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("HasTildePrefix(%q) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPathToFlatName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{"empty string", "", ""},
|
|
{"dot only", ".", ""},
|
|
{"single level", "my-skill", "my-skill"},
|
|
{"two levels", "personal/email", "personal__email"},
|
|
{"three levels", "_team/frontend/ui", "_team__frontend__ui"},
|
|
{"deep nesting", "a/b/c/d/e", "a__b__c__d__e"},
|
|
{"with leading slash", "/my-skill", "my-skill"},
|
|
{"with trailing slash", "my-skill/", "my-skill"},
|
|
{"with both slashes", "/my-skill/", "my-skill"},
|
|
{"windows backslash", "a\\b\\c", "a__b__c"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := PathToFlatName(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("PathToFlatName(%q) = %q, want %q", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFlatNameToPath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{"empty string", "", ""},
|
|
{"single level", "my-skill", "my-skill"},
|
|
{"two levels", "personal__email", "personal/email"},
|
|
{"three levels", "_team__frontend__ui", "_team/frontend/ui"},
|
|
{"deep nesting", "a__b__c__d__e", "a/b/c/d/e"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := FlatNameToPath(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("FlatNameToPath(%q) = %q, want %q", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPathToFlatNameRoundTrip(t *testing.T) {
|
|
paths := []string{
|
|
"my-skill",
|
|
"personal/email",
|
|
"_team/frontend/ui",
|
|
"a/b/c/d",
|
|
}
|
|
|
|
for _, path := range paths {
|
|
flat := PathToFlatName(path)
|
|
back := FlatNameToPath(flat)
|
|
if back != path {
|
|
t.Errorf("Round trip failed: %q -> %q -> %q", path, flat, back)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsTrackedRepoDir(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected bool
|
|
}{
|
|
{"empty string", "", false},
|
|
{"tracked repo", "_team-repo", true},
|
|
{"underscore only", "_", true},
|
|
{"normal dir", "my-skill", false},
|
|
{"nested flat name", "_team__ui", true},
|
|
{"underscore in middle", "my_skill", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := IsTrackedRepoDir(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("IsTrackedRepoDir(%q) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHasNestedSeparator(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected bool
|
|
}{
|
|
{"empty string", "", false},
|
|
{"no separator", "my-skill", false},
|
|
{"single underscore", "my_skill", false},
|
|
{"double underscore", "team__ui", true},
|
|
{"at start", "__prefix", true},
|
|
{"at end", "suffix__", true},
|
|
{"multiple", "a__b__c", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := HasNestedSeparator(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("HasNestedSeparator(%q) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|