From f6246d62404f3dfb6dd9beb49cc3a65c0bebd91c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 25 Mar 2026 23:18:26 +0200 Subject: rpn: Add unit test for exact user scenario with x =: incremental assignment --- internal/repl/repl_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'internal/repl/repl_test.go') 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) + } +} -- cgit v1.2.3