- Issue #4: currently there is no official release yet so we cant download from installer - I added an installer debugger here to test (f091dbf13bdf109b631951e2558651f560ca8b84) - Issue #5: my another library [fuzzy](https://github.com/versenilvis/fuzzy/) has a logic bug so it causes crash, fix d479c6cb4d8453e50366c9839daaabb45a98a2df - Other: - remove unneeded comments (edd9d05fdd16e682b6b416913e2fa9c3f6599956) - Add some tests - Fix reload crash (3a76e78e655fd8daafb635ec0937667325f75ee4) - New optimized build command (56a4a815f836271b861f32795d2df3b25a3dffc0)
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package tests
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/versenilvis/iris/commands/fs"
|
|
)
|
|
|
|
func TestZoxideGenerator(t *testing.T) {
|
|
// Setup: Create a mock zoxide binary
|
|
tmp := t.TempDir()
|
|
mockZoxide := filepath.Join(tmp, "zoxide")
|
|
|
|
// Script that prints mock directories
|
|
script := "#!/bin/sh\necho \"/home/verse/project1\n/home/verse/docs\n/home/verse/dev/iris\""
|
|
_ = os.WriteFile(mockZoxide, []byte(script), 0755)
|
|
|
|
// Add tmp to PATH
|
|
oldPath := os.Getenv("PATH")
|
|
_ = os.Setenv("PATH", tmp+string(os.PathListSeparator)+oldPath)
|
|
defer func() { _ = os.Setenv("PATH", oldPath) }()
|
|
|
|
gen := fs.ZoxideGenerator()
|
|
|
|
|
|
t.Run("Query returns correct result when partial is empty", func(t *testing.T) {
|
|
results := gen([]string{"z", ""}, "z ", "")
|
|
if len(results) == 0 {
|
|
t.Errorf("Expected results from zoxide history, got 0")
|
|
}
|
|
})
|
|
|
|
|
|
t.Run("Path replaces home dir with ~", func(t *testing.T) {
|
|
home, _ := os.UserHomeDir()
|
|
results := gen([]string{"z", ""}, "z ", "")
|
|
foundHome := false
|
|
for _, r := range results {
|
|
if strings.HasPrefix(r.Desc, "~") {
|
|
foundHome = true
|
|
break
|
|
}
|
|
}
|
|
if !foundHome && home != "" {
|
|
t.Logf("Warning: Did not find ~ in descriptions, home is %s", home)
|
|
}
|
|
})
|
|
|
|
|
|
t.Run("Sort by descending score", func(t *testing.T) {
|
|
results := gen([]string{"z", "i"}, "z ", "i")
|
|
if len(results) >= 1 {
|
|
if results[0].Cmd == "" {
|
|
t.Errorf("Empty result command")
|
|
}
|
|
}
|
|
})
|
|
}
|