From ffdc7b70f044e1f26c2f6fbb93b5495e4ebdb1ad Mon Sep 17 00:00:00 2001 From: derailed Date: Sat, 19 Jul 2025 09:27:46 -0600 Subject: [PATCH] [hot-fix] fix tests --- internal/view/cmd/interpreter.go | 15 ++++++------ internal/view/cmd/interpreter_test.go | 34 ++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/internal/view/cmd/interpreter.go b/internal/view/cmd/interpreter.go index b42dac35..a95cc4f6 100644 --- a/internal/view/cmd/interpreter.go +++ b/internal/view/cmd/interpreter.go @@ -29,17 +29,18 @@ func NewInterpreter(s string) *Interpreter { // ClearNS clears the current namespace if any. func (c *Interpreter) ClearNS() { - if !c.HasNS() { - return - } - if ons, ok := c.NSArg(); ok { - c.Reset(strings.TrimSpace(strings.Replace(c.line, " "+ons, "", 1))) - } + c.SwitchNS(client.BlankNamespace) } // SwitchNS replaces the current namespace with the provided one. func (c *Interpreter) SwitchNS(ns string) { - c.args[nsKey] = ns + if ons, ok := c.NSArg(); ok && ons != client.BlankNamespace { + c.Reset(strings.TrimSpace(strings.Replace(c.line, " "+ons, " "+ns, 1))) + return + } + if ns != client.BlankNamespace { + c.Reset(strings.TrimSpace(c.line) + " " + ns) + } } func (c *Interpreter) grok() { diff --git a/internal/view/cmd/interpreter_test.go b/internal/view/cmd/interpreter_test.go index 2672bf36..6fa6b532 100644 --- a/internal/view/cmd/interpreter_test.go +++ b/internal/view/cmd/interpreter_test.go @@ -85,10 +85,15 @@ func TestSwitchNS(t *testing.T) { }{ "empty": {}, + "blank": { + cmd: "pod fred", + e: "pod", + }, + "no-op": { cmd: "pod fred", - ns: "blee", - e: "pod blee", + ns: "fred", + e: "pod fred", }, "no-ns": { @@ -97,8 +102,20 @@ func TestSwitchNS(t *testing.T) { e: "pod blee", }, - "happy": { - cmd: "pod app=blee @zorg fred", + "full-ns": { + cmd: "pod app=blee fred @zorg", + ns: "blee", + e: "pod app=blee blee @zorg", + }, + + "full--repeat-ns": { + cmd: "pod app=zorg zorg @zorg", + ns: "blee", + e: "pod app=zorg blee @zorg", + }, + + "full-no-ns": { + cmd: "pod app=blee @zorg", ns: "blee", e: "pod app=blee @zorg blee", }, @@ -121,7 +138,7 @@ func TestClearNS(t *testing.T) { }{ "empty": {}, - "no-op": { + "has-ns": { cmd: "pod fred", e: "pod", }, @@ -131,10 +148,15 @@ func TestClearNS(t *testing.T) { e: "pod", }, - "happy": { + "full-repeat-ns": { cmd: "pod app=blee @zorg zorg", e: "pod app=blee @zorg", }, + + "full-no-ns": { + cmd: "pod app=blee @zorg", + e: "pod app=blee @zorg", + }, } for k := range uu {