diff options
author | Elwardi <elwardifadeli@gmail.com> | 2021-07-22 15:44:16 +0100 |
---|---|---|
committer | Elwardi <elwardifadeli@gmail.com> | 2021-07-22 15:44:16 +0100 |
commit | 148bf2c070ab6f9a7e559851ed4d05496e651552 (patch) | |
tree | 1d269751810ac71bdcc7820f6269fd72b9064022 /pkg/gui/gui_test.go | |
parent | edfb0a26b2bebb67520061df843aa95f78a981c0 (diff) |
Add test for GenerateMenuCandidates from Custom Commands
Diffstat (limited to 'pkg/gui/gui_test.go')
-rw-r--r-- | pkg/gui/gui_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index 8e37cecfe..8fcf0d4de 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -80,3 +80,52 @@ func runCmdHeadless(cmd *exec.Cmd) error { return f.Close() } + +func TestGuiGenerateMenuCandidates(t *testing.T) { + type scenario struct { + testName string + cmdOut string + filter string + format string + test func([]string, error) + } + + scenarios := []scenario{ + { + "Extract remote branch name", + "upstream/pr-1", + "upstream/(?P<branch>.*)", + "{{ .branch }}", + func(actual []string, err error) { + assert.NoError(t, err) + assert.EqualValues(t, "pr-1", actual[0]) + }, + }, + { + "Multiple named groups", + "upstream/pr-1", + "(?P<remote>[a-z]*)/(?P<branch>.*)", + "{{ .branch }}|{{ .remote }}", + func(actual []string, err error) { + assert.NoError(t, err) + assert.EqualValues(t, "pr-1|upstream", actual[0]) + }, + }, + { + "Multiple named groups with group ids", + "upstream/pr-1", + "(?P<remote>[a-z]*)/(?P<branch>.*)", + "{{ .group_2 }}|{{ .group_1 }}", + func(actual []string, err error) { + assert.NoError(t, err) + assert.EqualValues(t, "pr-1|upstream", actual[0]) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + s.test(NewDummyGui().GenerateMenuCandidates(s.cmdOut, s.filter, s.format)) + }) + } +} |