From 4a0bdeb98cd28388780239e5bec9488d1a75c19e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 25 Mar 2026 23:09:34 +0200 Subject: rpn: Fix incremental assignment with x =: (take value from stack) --- internal/repl/repl_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'internal/repl') diff --git a/internal/repl/repl_test.go b/internal/repl/repl_test.go index b07036e..f4b95ea 100644 --- a/internal/repl/repl_test.go +++ b/internal/repl/repl_test.go @@ -684,3 +684,45 @@ func TestExecutorWithIncrementalAssignment(t *testing.T) { t.Errorf("Variable z = %v, want 3", val) } } + +// TestExecutorWithSimpleIncrementalAssignment tests x =: after 2 in REPL +func TestExecutorWithSimpleIncrementalAssignment(t *testing.T) { + // First execute 2 to put it on the stack + executor("2") + state := getRPNState() + + // Then use x =: to assign the top of stack to variable x + executor("x =:") + 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) + } +} + +// TestExecutorWithExactUserScenario tests the exact user scenario: 2 then x =: +func TestExecutorWithExactUserScenario(t *testing.T) { + // This test replicates the exact user interaction: + // > 2 + // > x =: + // The variable should be assigned the value 2 + + executor("2") + state := getRPNState() + + // Verify stack has 2 + // (can't directly check stack without exposing it, but next command will fail if stack is empty) + + executor("x =:") + 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