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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Paul Buetow
package repl
import (
"strings"
"testing"
)
func TestCommands(t *testing.T) {
cmds := Commands()
if len(cmds) == 0 {
t.Error("Commands() should return at least one command")
}
}
func TestExecuteCommandRPN(t *testing.T) {
_, err := ExecuteCommand("rpn")
if err != nil {
t.Fatalf("ExecuteCommand('rpn') returned error: %v", err)
}
}
func TestExecuteCommandCalc(t *testing.T) {
_, err := ExecuteCommand("calc")
if err != nil {
t.Fatalf("ExecuteCommand('calc') returned error: %v", err)
}
}
func TestExecuteCommandHelpWithUnknownSubcommand(t *testing.T) {
output, err := ExecuteCommand("help unknown")
if err != nil {
t.Fatalf("ExecuteCommand('help unknown') returned error: %v", err)
}
if !strings.Contains(output, "No help for") {
t.Errorf("ExecuteCommand('help unknown') should mention 'No help for', got: %s", output[:80])
}
}
func TestExecuteCommandHelpForHelp(t *testing.T) {
output, err := ExecuteCommand("help help")
if err != nil {
t.Fatalf("ExecuteCommand('help help') returned error: %v", err)
}
if !strings.Contains(output, "help") {
t.Errorf("ExecuteCommand('help help') output should contain 'help', got: %s", output[:50])
}
}
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, "gt") {
t.Errorf("ExecuteCommand('help') output should contain 'gt', got: %s", output[:80])
}
if !strings.Contains(output, "RPN") {
t.Errorf("ExecuteCommand('help') output should mention RPN, got: %s", output[:80])
}
}
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)
}
}
func TestCmdStack(t *testing.T) {
output := cmdStack()
expected := "Use 'rpn show' to view the current stack state"
if output != expected {
t.Errorf("cmdStack() = %q, want %q", output, expected)
}
}
|