-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(help): add full help test to support #554
- Loading branch information
1 parent
d3dc455
commit a9c714a
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package help | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"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 i, w := range []int{20, 30, 40} { | ||
m.Width = w | ||
s := m.FullHelpView(kb) | ||
|
||
dir := "testdata" | ||
filename := filepath.Join(dir, fmt.Sprintf("full_help_%d.golden", i)) | ||
|
||
// Un-comment to generate golden files | ||
// if err := os.MkdirAll(dir, 0755); err != nil { | ||
// t.Error(err) | ||
// } | ||
// if err := os.WriteFile(filename, []byte(s), 0644); err != nil { | ||
// t.Error(err) | ||
// } | ||
|
||
b, err := os.ReadFile(filename) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if s != string(b) { | ||
t.Errorf("Expected:\n%q, Got:\n%q", b, s) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
enter continue … |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
enter continue | esc back … | ||
? help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |