1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Paul Buetow
package repl
import (
"strings"
"testing"
)
// TestCompleterLogic tests the completer logic directly
func TestCompleterLogic(t *testing.T) {
testCases := []struct {
name string
text string
match bool
}{
{"h", "h", true},
{"he", "he", true},
{"hel", "hel", true},
{"help", "help", true},
{"c", "c", true},
{"cl", "cl", true},
{"cle", "cle", true},
{"clear", "clear", true},
{"ca", "ca", true},
{"cal", "cal", true},
{"calc", "calc", true},
{"q", "q", true},
{"qu", "qu", true},
{"qui", "qui", true},
{"quit", "quit", true},
{"e", "e", true},
{"ex", "ex", true},
{"exi", "exi", true},
{"exit", "exit", true},
{"r", "r", true},
{"rp", "rp", true},
{"rpn", "rpn", true},
{"x", "x", false},
{"xyz", "xyz", false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
suggestions := completer(tc.text)
found := false
for _, s := range suggestions {
if strings.HasPrefix(strings.ToLower(s), strings.ToLower(tc.text)) {
found = true
break
}
}
if found != tc.match {
t.Errorf("For text %q, expected match=%v, got match=%v", tc.text, tc.match, found)
}
})
}
}
// TestCompleterEmptyText tests completer with empty text
func TestCompleterEmptyText(t *testing.T) {
suggestions := completer("")
if suggestions != nil {
t.Errorf("Expected nil for empty text, got %d suggestions", len(suggestions))
}
}
// TestCompleterNoPrefix tests completer with no matching prefix
func TestCompleterNoPrefix(t *testing.T) {
suggestions := completer("xyz ")
if len(suggestions) > 0 {
t.Errorf("Expected no suggestions for 'xyz', got %d", len(suggestions))
}
}
|