From 36c98a0e109e49c72f446e004352da87a76a50f3 Mon Sep 17 00:00:00 2001 From: Mike McGann Date: Wed, 28 Feb 2024 17:06:17 -0500 Subject: [PATCH] fix quote prompt, blank quote lines, add end quote to prompt --- pkg/repl/commands.go | 4 +++- pkg/repl/repl.go | 2 +- pkg/repl/repl_test.go | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/repl/commands.go b/pkg/repl/commands.go index 87cf571a..5e6f9547 100644 --- a/pkg/repl/commands.go +++ b/pkg/repl/commands.go @@ -62,7 +62,9 @@ func def(r *REPL, s *scan.Scanner) error { } func pop(r *REPL, _ *scan.Scanner) error { - r.Calc.Pop() + if r.quoteEnd == "" { + r.Calc.Pop() + } return nil } diff --git a/pkg/repl/repl.go b/pkg/repl/repl.go index 85e6562c..660c837f 100644 --- a/pkg/repl/repl.go +++ b/pkg/repl/repl.go @@ -176,7 +176,7 @@ func (r *REPL) saveHistory() { func (r *REPL) getPrompt() string { if r.quoteEnd != "" { - return "...>" + return fmt.Sprintf("... %s> ", r.quoteEnd) } return zc.ProgName + " > " } diff --git a/pkg/repl/repl_test.go b/pkg/repl/repl_test.go index 280c64cd..c3c1c5ab 100644 --- a/pkg/repl/repl_test.go +++ b/pkg/repl/repl_test.go @@ -70,6 +70,25 @@ func TestQuote(t *testing.T) { } } +func TestQuoteBlanks(t *testing.T) { + ansi.Enabled = false + c := calc.New() + repl := New(c) + + repl.Eval("quote EOF") + repl.Eval("1 2 add") + repl.Eval("2 3 sub") + repl.Eval("") + repl.Eval("") + repl.Eval("EOF") + + have := c.Stack() + want := []string{"1 2 add", "2 3 sub"} + if !reflect.DeepEqual(have, want) { + t.Fatalf("\n have: %v \n want: %v", have, want) + } +} + func TestCommonPrefix(t *testing.T) { tests := []struct { common string