From e7177107a7bb06ede812151dc06257d5a096eb40 Mon Sep 17 00:00:00 2001 From: Edznux Date: Thu, 25 Oct 2018 18:46:13 +0200 Subject: [PATCH] Add more ParseCommand tests --- session/session_test.go | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/session/session_test.go b/session/session_test.go index 29edcef3..d154ed89 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -35,4 +35,56 @@ func TestParseCommands(t *testing.T) { t.Fatalf("expected %s got %s", cmd, got) } }) + t.Run("handles semicolon inside single quotes", func(t *testing.T) { + cmd := "set ticker.commands 'clear; net.show'" + commands := ParseCommands(cmd) + if l := len(commands); l != 1 { + t.Fatalf("expected 1 command, got %d", l) + } + // Expect double-quotes stripped + expected := "set ticker.commands clear; net.show" + if got := commands[0]; got != expected { + fmt.Println(got) + t.Fatalf("expected %s got %s", cmd, got) + } + }) + t.Run("handles semicolon inside single quotes inside quote", func(t *testing.T) { + cmd := "set ticker.commands \"'clear; net.show'\"" + commands := ParseCommands(cmd) + if l := len(commands); l != 1 { + t.Fatalf("expected 1 command, got %d", l) + } + // Expect double-quotes stripped + expected := "set ticker.commands 'clear; net.show'" + if got := commands[0]; got != expected { + fmt.Println(got) + t.Fatalf("expected %s got %s", cmd, got) + } + }) + t.Run("handles semicolon inside quotes inside single quote", func(t *testing.T) { + cmd := "set ticker.commands '\"clear; net.show\"'" + commands := ParseCommands(cmd) + if l := len(commands); l != 1 { + t.Fatalf("expected 1 command, got %d", l) + } + // Expect double-quotes stripped + expected := "set ticker.commands \"clear; net.show\"" + if got := commands[0]; got != expected { + fmt.Println(got) + t.Fatalf("expected %s got %s", cmd, got) + } + }) + t.Run("handle mismatching quote", func(t *testing.T) { + cmd := "set ticker.commands \"clear; echo it's working ?\"" + commands := ParseCommands(cmd) + if l := len(commands); l != 1 { + t.Fatalf("expected 1 command, got %d", l) + } + // Expect double-quotes stripped + expected := "set ticker.commands clear; echo it's working ?" + if got := commands[0]; got != expected { + fmt.Println(got) + t.Fatalf("expected %s got %s", cmd, got) + } + }) }