- I think it would be better if one for commands only, one for the spec handling core logic so people won't be confused by the core logic inside the commands folder (cleaner I guess) - Regen docs
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package tests
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/versenilvis/iris/spec"
|
|
)
|
|
|
|
func TestTokenize(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected []string
|
|
}{
|
|
{"Empty input", "", []string{""}},
|
|
{"Trailing space", "git ", []string{"git", ""}},
|
|
{"Multi-space", "git add", []string{"git", "add"}},
|
|
{"Quoted string", "git commit -m \"hello world\"", []string{"git", "commit", "-m", "hello world"}},
|
|
{"Quote not closed", "git commit -m \"hello", []string{"git", "commit", "-m", "hello"}},
|
|
{"Single quote", "git commit -m 'hello world'", []string{"git", "commit", "-m", "hello world"}},
|
|
{"Backslash escape", "git commit -m \"hello\\ world\"", []string{"git", "commit", "-m", "hello world"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := spec.Tokenize(tt.input)
|
|
if !reflect.DeepEqual(got, tt.expected) {
|
|
t.Errorf("Tokenize(%q) = %v; want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHasPrefix(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
s string
|
|
prefix string
|
|
want bool
|
|
}{
|
|
{"Case insensitive", "Hello", "hel", true},
|
|
{"Unicode support", "Thử nghiệm", "thử", true},
|
|
{"Prefix longer", "Iris", "Iris-Longer", false},
|
|
{"Empty prefix", "Iris", "", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := spec.HasPrefix(tt.s, tt.prefix); got != tt.want {
|
|
t.Errorf("HasPrefix(%q, %q) = %v; want %v", tt.s, tt.prefix, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|