Skip to content

Commit

Permalink
chore(help): add full help test to support #554
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Oct 11, 2024
1 parent 81d444a commit 6079650
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/charmbracelet/harmonica v0.2.0
github.com/charmbracelet/lipgloss v0.13.0
github.com/charmbracelet/x/ansi v0.3.2
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91
github.com/dustin/go-humanize v1.0.1
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-runewidth v0.0.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY=
github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q=
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
38 changes: 38 additions & 0 deletions help/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package help

import (
"fmt"
"testing"

"github.com/charmbracelet/x/exp/golden"

"github.com/charmbracelet/bubbles/key"
)

func TestFullHelp(t *testing.T) {
m := New()
m.FullSeparator = " | "
k := key.WithKeys("x")
kb := [][]key.Binding{
{
key.NewBinding(k, key.WithHelp("enter", "continue")),
},
{
key.NewBinding(k, key.WithHelp("esc", "back")),
key.NewBinding(k, key.WithHelp("?", "help")),
},
{
key.NewBinding(k, key.WithHelp("H", "home")),
key.NewBinding(k, key.WithHelp("ctrl+c", "quit")),
key.NewBinding(k, key.WithHelp("ctrl+l", "log")),
},
}

for _, w := range []int{20, 30, 40} {
t.Run(fmt.Sprintf("full help %d width", w), func(t *testing.T) {
m.Width = w
s := m.FullHelpView(kb)
golden.RequireEqual(t, []byte(s))
})
}
}
1 change: 1 addition & 0 deletions help/testdata/TestFullHelp/full_help_20_width.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enter continue …
2 changes: 2 additions & 0 deletions help/testdata/TestFullHelp/full_help_30_width.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
enter continue | esc back …
? help
3 changes: 3 additions & 0 deletions help/testdata/TestFullHelp/full_help_40_width.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enter continue | esc back | H home
? help ctrl+c quit
ctrl+l log

0 comments on commit 6079650

Please sign in to comment.