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
|
package repl
import (
"strings"
"testing"
)
func TestExecuteCommandHelp(t *testing.T) {
output, err := ExecuteCommand("help")
if err != nil {
t.Fatalf("ExecuteCommand('help') returned error: %v", err)
}
if output == "" {
t.Error("ExecuteCommand('help') returned empty output")
}
if !strings.Contains(output, "PERC") {
t.Errorf("ExecuteCommand('help') output should contain 'PERC', got: %s", output[:50])
}
}
func TestExecuteCommandHelpWithSubcommand(t *testing.T) {
output, err := ExecuteCommand("help clear")
if err != nil {
t.Fatalf("ExecuteCommand('help clear') returned error: %v", err)
}
if output == "" {
t.Error("ExecuteCommand('help clear') returned empty output")
}
if !strings.Contains(output, "Clear") {
t.Errorf("ExecuteCommand('help clear') output should contain 'Clear', got: %s", output[:50])
}
}
func TestExecuteCommandUnknownCommand(t *testing.T) {
_, err := ExecuteCommand("unknown")
if err == nil {
t.Error("ExecuteCommand('unknown') should return error, got nil")
}
if !strings.Contains(err.Error(), "unknown command") {
t.Errorf("Error should mention 'unknown command', got: %v", err)
}
}
func TestExecuteCommandClear(t *testing.T) {
_, err := ExecuteCommand("clear")
if err != nil {
t.Fatalf("ExecuteCommand('clear') returned error: %v", err)
}
}
func TestExecuteCommandQuit(t *testing.T) {
_, err := ExecuteCommand("quit")
if err != nil {
t.Fatalf("ExecuteCommand('quit') returned error: %v", err)
}
}
func TestExecuteCommandExit(t *testing.T) {
_, err := ExecuteCommand("exit")
if err != nil {
t.Fatalf("ExecuteCommand('exit') returned error: %v", err)
}
}
func TestExecuteCommandEmpty(t *testing.T) {
_, err := ExecuteCommand("")
if err != nil {
t.Fatalf("ExecuteCommand('') returned error: %v", err)
}
}
|