- 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)
This commit is contained in:
@@ -22,7 +22,7 @@ func TestFileGenerator(t *testing.T) {
|
||||
_ = os.Chdir(tmp)
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
|
||||
// REQUIREMENT: dirOnly shows only dirs
|
||||
|
||||
t.Run("dirOnly shows only dirs", func(t *testing.T) {
|
||||
gen := core.FileGenerator("/")
|
||||
results := gen([]string{"cd", ""}, "cd ", "")
|
||||
@@ -33,7 +33,7 @@ func TestFileGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Filter extension shows only matching files
|
||||
|
||||
t.Run("Filter extension", func(t *testing.T) {
|
||||
gen := core.FileGenerator(".go")
|
||||
results := gen([]string{"ls", ""}, "ls ", "")
|
||||
@@ -51,7 +51,7 @@ func TestFileGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Nested path (src/mai -> correct dir + prefix)
|
||||
|
||||
t.Run("Nested path", func(t *testing.T) {
|
||||
gen := core.FileGenerator()
|
||||
results := gen([]string{"ls", "src/u"}, "ls src/u", "src/u")
|
||||
@@ -66,7 +66,7 @@ func TestFileGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Deep scan 1 level finds files in subdir
|
||||
|
||||
t.Run("Deep scan 1 level", func(t *testing.T) {
|
||||
gen := core.FileGenerator()
|
||||
results := gen([]string{"ls", "src/"}, "ls src/", "src/")
|
||||
@@ -81,10 +81,9 @@ func TestFileGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Deep scan does not go deeper than 1 level
|
||||
// (This is implicitly tested by the logic in FileGenerator)
|
||||
|
||||
// REQUIREMENT: Hidden files are skipped
|
||||
|
||||
|
||||
t.Run("Hidden files are skipped", func(t *testing.T) {
|
||||
gen := core.FileGenerator()
|
||||
results := gen([]string{"ls", ""}, "ls ", "")
|
||||
|
||||
@@ -2,6 +2,7 @@ package tests
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
@@ -31,21 +32,13 @@ func TestLookup(t *testing.T) {
|
||||
minResults int
|
||||
mustContain string
|
||||
}{
|
||||
// REQUIREMENT: Token 1, no trailing space -> top-level suggestions
|
||||
{"Top-level", "gi", 1, "git"},
|
||||
// REQUIREMENT: Token 1, with trailing space -> subcommand suggestions
|
||||
{"Subcommand", "git ", 1, "git commit"},
|
||||
// REQUIREMENT: Alias expansion (gca -> git commit -a)
|
||||
{"Alias expansion", "gca", 1, "git commit -a"},
|
||||
// REQUIREMENT: Alias value with space (ta -> tmux a -t)
|
||||
{"Alias with space", "ta", 1, "tmux a -t"},
|
||||
// REQUIREMENT: Subcommand depth 2+ (git remote add)
|
||||
{"Deep subcommand", "git remote ", 1, "git remote add"},
|
||||
// REQUIREMENT: Option dedup (do not suggest --verbose if already typed)
|
||||
{"Option dedup", "git --verbose -", 0, ""},
|
||||
// REQUIREMENT: --flag=value does not count into argCount
|
||||
{"Option dedup", "git --verbose -", 0, ""},
|
||||
{"Flag with value ignore", "git --output=json ", 2, "git --output=json commit"},
|
||||
// REQUIREMENT: Unknown root command -> nil
|
||||
{"Unknown root command", "unknowncmd ", 0, ""},
|
||||
}
|
||||
|
||||
@@ -70,3 +63,33 @@ func TestLookup(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupConcurrent(t *testing.T) {
|
||||
core.Registry = make(map[string]*core.Spec)
|
||||
core.Register(&core.Spec{
|
||||
Name: "git",
|
||||
Subcommands: []core.Subcommand{
|
||||
{Name: "commit", Options: []core.Option{{Name: "--message"}}, MaxArgs: 1},
|
||||
},
|
||||
})
|
||||
|
||||
core.ShellAliases = map[string]string{
|
||||
"gca": "git commit -a",
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
const goroutines = 10
|
||||
const iterations = 50
|
||||
|
||||
for range goroutines {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for range iterations {
|
||||
_ = core.Lookup("gca")
|
||||
_ = core.Lookup("git ")
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -13,19 +13,12 @@ func TestTokenize(t *testing.T) {
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
// REQUIREMENT: Empty input
|
||||
{"Empty input", "", []string{""}},
|
||||
// REQUIREMENT: Trailing space("git " -> 2 tokens, the last token is "")
|
||||
{"Trailing space", "git ", []string{"git", ""}},
|
||||
// REQUIREMENT: Multi-space("git add")
|
||||
{"Multi-space", "git add", []string{"git", "add"}},
|
||||
// REQUIREMENT: Quoted string("git commit -m \"hello world\"")
|
||||
{"Quoted string", "git commit -m \"hello world\"", []string{"git", "commit", "-m", "hello world"}},
|
||||
// REQUIREMENT: Quote not closed
|
||||
{"Quote not closed", "git commit -m \"hello", []string{"git", "commit", "-m", "hello"}},
|
||||
// REQUIREMENT: Single quote vs double quote
|
||||
{"Single quote", "git commit -m 'hello world'", []string{"git", "commit", "-m", "hello world"}},
|
||||
// REQUIREMENT: Backslash escape
|
||||
{"Backslash escape", "git commit -m \"hello\\ world\"", []string{"git", "commit", "-m", "hello world"}},
|
||||
}
|
||||
|
||||
@@ -46,13 +39,9 @@ func TestHasPrefix(t *testing.T) {
|
||||
prefix string
|
||||
want bool
|
||||
}{
|
||||
// REQUIREMENT: Case insensitive match
|
||||
{"Case insensitive", "Hello", "hel", true},
|
||||
// REQUIREMENT: Unicode support (Vietnamese)
|
||||
{"Unicode support", "Thử nghiệm", "thử", true},
|
||||
// REQUIREMENT: Prefix longer than string -> false
|
||||
{"Prefix longer", "Iris", "Iris-Longer", false},
|
||||
// REQUIREMENT: Empty prefix -> true
|
||||
{"Empty prefix", "Iris", "", true},
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestZoxideGenerator(t *testing.T) {
|
||||
|
||||
gen := fs.ZoxideGenerator()
|
||||
|
||||
// REQUIREMENT: Query returns the correct result when partial = ""
|
||||
|
||||
t.Run("Query returns correct result when partial is empty", func(t *testing.T) {
|
||||
results := gen([]string{"z", ""}, "z ", "")
|
||||
if len(results) == 0 {
|
||||
@@ -33,7 +33,7 @@ func TestZoxideGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Path replaces home dir with ~
|
||||
|
||||
t.Run("Path replaces home dir with ~", func(t *testing.T) {
|
||||
home, _ := os.UserHomeDir()
|
||||
results := gen([]string{"z", ""}, "z ", "")
|
||||
@@ -49,7 +49,7 @@ func TestZoxideGenerator(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Sort by descending score
|
||||
|
||||
t.Run("Sort by descending score", func(t *testing.T) {
|
||||
results := gen([]string{"z", "i"}, "z ", "i")
|
||||
if len(results) >= 1 {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMergeResults(t *testing.T) {
|
||||
// REQUIREMENT: Dedup exact match
|
||||
|
||||
t.Run("Dedup exact match", func(t *testing.T) {
|
||||
// Mock history items that might conflict with specs
|
||||
res := root.MergeResults("git", "spec")
|
||||
@@ -20,7 +20,7 @@ func TestMergeResults(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// REQUIREMENT: Limit 100
|
||||
|
||||
t.Run("Limit 100", func(t *testing.T) {
|
||||
res := root.MergeResults("a", "history")
|
||||
if len(res) > 100 {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestScanPosixAliases(t *testing.T) {
|
||||
// REQUIREMENT: Parse single alias, multi alias, comments, value with space
|
||||
|
||||
input := `
|
||||
alias gca='git commit -a'
|
||||
alias ta="tmux a -t" # this is a comment
|
||||
@@ -34,10 +34,10 @@ func TestSplitAliasTokens(t *testing.T) {
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
// REQUIREMENT: Parse multi alias on one line
|
||||
|
||||
{"Single", "a='b'", []string{"a='b'"}},
|
||||
{"Multi", "a='b' c=\"d\"", []string{"a='b'", "c=\"d\""}},
|
||||
// REQUIREMENT: Value with space in quote
|
||||
|
||||
{"With Space", "ta='tmux a -t' l='ls -l'", []string{"ta='tmux a -t'", "l='ls -l'"}},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user