summaryrefslogtreecommitdiff
path: root/internal/repl/repl_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-25 23:18:26 +0200
committerPaul Buetow <paul@buetow.org>2026-03-25 23:18:26 +0200
commitf6246d62404f3dfb6dd9beb49cc3a65c0bebd91c (patch)
treed3dc9f0b29c2e1e43afe6e51d4889b786210eb94 /internal/repl/repl_test.go
parentd8c61e5214a9782561894f2de697826aca7605e9 (diff)
rpn: Add unit test for exact user scenario with x =: incremental assignment
Diffstat (limited to 'internal/repl/repl_test.go')
-rw-r--r--internal/repl/repl_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/repl/repl_test.go b/internal/repl/repl_test.go
index f4b95ea..bf5af49 100644
--- a/internal/repl/repl_test.go
+++ b/internal/repl/repl_test.go
@@ -726,3 +726,49 @@ func TestExecutorWithExactUserScenario(t *testing.T) {
t.Errorf("Variable x = %v, want 2", val)
}
}
+
+// TestExecutorWithExactUserScenarioWithOutput tests that x =: assigns and shows result
+func TestExecutorWithExactUserScenarioWithOutput(t *testing.T) {
+ // First, clear state
+ executor("rpn clear")
+
+ // Put 2 on stack
+ executor("2")
+ state := getRPNState()
+ _, _ = state.rpnCalc.ResultStack([]string{})
+
+ // Assign to x =:
+ result, err := state.rpnCalc.ParseAndEvaluate("x =:")
+ t.Logf("ParseAndEvaluate('x =:') returned result=%q, err=%v", result, err)
+
+ state = getRPNState()
+ val, exists := state.vars.GetVariable("x")
+ if !exists {
+ t.Errorf("Variable x should exist after x =:")
+ }
+ if val != 2 {
+ t.Errorf("Variable x = %v, want 2", val)
+ }
+}
+
+// TestExecutorWithExactUserScenarioDirect simulates REPL input flow
+func TestExecutorWithExactUserScenarioDirect(t *testing.T) {
+ // Clear any previous state
+ executor("rpn clear")
+
+ // Simulate typing "2" in REPL
+ executor("2")
+
+ // Simulate typing "x =:" in REPL
+ executor("x =:")
+
+ // Verify variable was set
+ state := getRPNState()
+ val, exists := state.vars.GetVariable("x")
+ if !exists {
+ t.Errorf("Variable x should exist after x =:")
+ }
+ if val != 2 {
+ t.Errorf("Variable x = %v, want 2", val)
+ }
+}