diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-22 20:18:40 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-22 21:33:17 +1100 |
commit | 2008c3951616f9b366b320e805dcbd0c5da6ce96 (patch) | |
tree | 5d4efb2a961acd1cdeca293e2771f8a34764cfcb /pkg/gui/gui_test.go | |
parent | 6388af70acda91bf1bdc9cba9f38dc810f49f9ca (diff) |
add tests for dealing with remotes
Diffstat (limited to 'pkg/gui/gui_test.go')
-rw-r--r-- | pkg/gui/gui_test.go | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/pkg/gui/gui_test.go b/pkg/gui/gui_test.go index 20fec1b37..6e7a26b79 100644 --- a/pkg/gui/gui_test.go +++ b/pkg/gui/gui_test.go @@ -56,8 +56,8 @@ func Test(t *testing.T) { updateSnapshots, record, speedEnv, - func(t *testing.T, expected string, actual string) { - assert.Equal(t, expected, actual, fmt.Sprintf("expected:\n%s\nactual:\n%s\n", expected, actual)) + func(t *testing.T, expected string, actual string, prefix string) { + assert.Equal(t, expected, actual, fmt.Sprintf("Unexpected %s. Expected:\n%s\nActual:\n%s\n", prefix, expected, actual)) }, includeSkipped, ) @@ -81,59 +81,3 @@ func runCmdHeadless(cmd *exec.Cmd) error { return f.Close() } - -func TestGuiGenerateMenuCandidates(t *testing.T) { - type scenario struct { - testName string - cmdOut string - filter string - valueFormat string - labelFormat string - test func([]commandMenuEntry, error) - } - - scenarios := []scenario{ - { - "Extract remote branch name", - "upstream/pr-1", - "(?P<remote>[a-z_]+)/(?P<branch>.*)", - "{{ .branch }}", - "Remote: {{ .remote }}", - func(actualEntry []commandMenuEntry, err error) { - assert.NoError(t, err) - assert.EqualValues(t, "pr-1", actualEntry[0].value) - assert.EqualValues(t, "Remote: upstream", actualEntry[0].label) - }, - }, - { - "Multiple named groups with empty labelFormat", - "upstream/pr-1", - "(?P<remote>[a-z]*)/(?P<branch>.*)", - "{{ .branch }}|{{ .remote }}", - "", - func(actualEntry []commandMenuEntry, err error) { - assert.NoError(t, err) - assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value) - assert.EqualValues(t, "pr-1|upstream", actualEntry[0].label) - }, - }, - { - "Multiple named groups with group ids", - "upstream/pr-1", - "(?P<remote>[a-z]*)/(?P<branch>.*)", - "{{ .group_2 }}|{{ .group_1 }}", - "Remote: {{ .group_1 }}", - func(actualEntry []commandMenuEntry, err error) { - assert.NoError(t, err) - assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value) - assert.EqualValues(t, "Remote: upstream", actualEntry[0].label) - }, - }, - } - - for _, s := range scenarios { - t.Run(s.testName, func(t *testing.T) { - s.test(NewDummyGui().GenerateMenuCandidates(s.cmdOut, s.filter, s.valueFormat, s.labelFormat)) - }) - } -} |