- commit
- c09a61f96a7ceeba310278a6d1311a50dc2a5e24
- parent
- c1ff31a7cb4e6900790f1927e11e4e836a46f1c0
- author
- Dami <dami.etoile@gmail.com>
| A | internal/ | 44 | ++++++++++++++++++++++++++++++ |
@@ -0,0 +1,44 @@
1+package theme2+3+import (4+ "testing"5+6+ "github.com/charmbracelet/x/ansi"7+)8+9+func TestKeyLabel(t *testing.T) {10+ for in, want := range map[string]string{11+ "ctrl+s": "Ctrl+S",12+ "f10": "F10",13+ "delete": "Del",14+ "esc": "Esc",15+ "alt+pgdown": "Alt+PgDn",16+ "ctrl+shift+p": "Ctrl+Shift+P",17+ } {18+ if got := KeyLabel(in); got != want {19+ t.Errorf("KeyLabel(%q) = %q, want %q", in, got, want)20+ }21+ }22+}23+24+func TestFrameKeepsEveryLineTheSameWidth(t *testing.T) {25+ th := New(true)26+ lines := th.Frame(12, "A long title that won't fit", "3 of 9", []string{PadRight("row", 12), SepRow, Cells(th.MenuBar, "a row that is too long", 12)})27+ if len(lines) != 5 {28+ t.Fatalf("%d lines, want 5", len(lines))29+ }30+ for i, l := range lines {31+ if w := ansi.StringWidth(l); w != 14 {32+ t.Errorf("line %d is %d wide: %q", i, w, ansi.Strip(l))33+ }34+ }35+ if got := ansi.Strip(lines[4]); got != "└─── 3 of 9 ─┘" {36+ t.Errorf("footer %q", got)37+ }38+}39+40+func TestPadding(t *testing.T) {41+ if got := PadLeft("7", 3) + "|" + PadRight("7", 3) + "|" + Center("ab", 5); got != " 7|7 | ab " {42+ t.Errorf("got %q", got)43+ }44+}