summaryrefslogtreecommitdiff
path: root/internal/repl/repl_test.go
blob: 53a707a0a2b4890180d41a29af2510b3e03d6028 (plain)
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
package repl

import (
	"testing"

	"github.com/c-bata/go-prompt"
)

func TestExecutor(t *testing.T) {
	// Test that executor doesn't panic on empty input
	executor("")
}

func TestExecutorWithHelp(t *testing.T) {
	// Test executor with help command
	// This should execute the help command and not print output
	executor("help")
}

func TestExecutorWithClear(t *testing.T) {
	executor("clear")
}

func TestExecutorWithQuit(t *testing.T) {
	// This should exit REPL but we can't test the actual exit
	// We just verify the command is processed without error
	executor("quit")
}

func TestExecutorWithExit(t *testing.T) {
	executor("exit")
}

func TestExecutorWithPercentage(t *testing.T) {
	// Test executor with a percentage calculation
	// Note: output is printed to stdout, we just verify it doesn't panic
	executor("20% of 150")
}

func TestExecutorWithRPN(t *testing.T) {
	// Test executor with RPN command
	executor("rpn 3 4 +")
}

func TestExecutorWithInvalid(t *testing.T) {
	// Test executor with invalid input
	executor("invalid input")
}

// Note: captureOutput is removed - we test for side effects instead of capturing output

func TestExecutorWithVars(t *testing.T) {
	executor("rpn x 5 = vars")
}

func TestExecutorWithClearVariables(t *testing.T) {
	executor("rpn clear")
}

func TestIsBuiltinCommand(t *testing.T) {
	// Test known built-in commands
	tests := []struct {
		input    string
		expected bool
	}{
		{"help", true},
		{"clear", true},
		{"quit", true},
		{"exit", true},
		{"rpn", true},
		{"calc", true},
		{"20% of 150", false},
		{"invalid", false},
	}

	for _, tt := range tests {
		t.Run(tt.input, func(t *testing.T) {
			_, ok := isBuiltinCommand(tt.input)
			if ok != tt.expected {
				t.Errorf("isBuiltinCommand(%q) = %v, want %v", tt.input, ok, tt.expected)
			}
		})
	}
}

func TestIsBuiltinCommandWithSubcommand(t *testing.T) {
	// Test with help subcommands
	_, ok := isBuiltinCommand("help clear")
	if !ok {
		t.Error("isBuiltinCommand('help clear') should return true")
	}
}

func TestCompleter(t *testing.T) {
	// Test completer with empty input
	suggestions := completer(prompt.Document{})
	// completer returns suggestions for builtin commands
	// We just verify it doesn't panic
	_ = suggestions
}

func TestCompleterWithPartialMatch(t *testing.T) {
	// Test completer with partial command
	suggestions := completer(prompt.Document{Text: "h"})
	// completer returns suggestions for builtin commands
	_ = suggestions
}

func TestCompleterWithClearPrefix(t *testing.T) {
	suggestions := completer(prompt.Document{Text: "cl"})
	_ = suggestions
}