Files
iris-context/tests/core/utils_test.go
T
VERSE d06526cf21 Fix: issue #4 and #5 (#6)
- 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)
2026-05-23 23:22:04 +07:00

56 lines
1.5 KiB
Go

package tests
import (
"reflect"
"testing"
"github.com/versenilvis/iris/commands/core"
)
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 := core.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 := core.HasPrefix(tt.s, tt.prefix); got != tt.want {
t.Errorf("HasPrefix(%q, %q) = %v; want %v", tt.s, tt.prefix, got, tt.want)
}
})
}
}