github.com/wtfutil/wtf@v0.43.0/view/base_test.go (about) 1 package view 2 3 import ( 4 "testing" 5 6 "github.com/rivo/tview" 7 "github.com/stretchr/testify/assert" 8 "github.com/wtfutil/wtf/cfg" 9 ) 10 11 func Benchmark_ContextualTitle(b *testing.B) { 12 b.ReportAllocs() 13 14 base := NewBase( 15 tview.NewApplication(), 16 make(chan bool), 17 tview.NewPages(), 18 &cfg.Common{}, 19 ) 20 base.SetFocusChar("a") 21 22 defaultStr := "This is test" 23 24 for i := 0; i < b.N; i++ { 25 _ = base.ContextualTitle(defaultStr) 26 } 27 } 28 29 func Test_ContextualTitle(t *testing.T) { 30 tests := []struct { 31 name string 32 defaultStr string 33 focusChar string 34 expected string 35 }{ 36 { 37 name: "with empty defaultStr and empty focusChar", 38 defaultStr: "", 39 focusChar: "", 40 expected: "", 41 }, 42 { 43 name: "with valid defaultStr and empty focusChar", 44 defaultStr: "cats", 45 focusChar: "", 46 expected: " cats ", 47 }, 48 { 49 name: "with empty defaultStr and valid focusChar", 50 defaultStr: "", 51 focusChar: "a", 52 expected: " [darkgray::u]a[::-][white] ", 53 }, 54 { 55 name: "with valid defaultStr and valid focusChar", 56 defaultStr: "cats", 57 focusChar: "a", 58 expected: " cats [darkgray::u]a[::-][white] ", 59 }, 60 } 61 62 for _, tt := range tests { 63 t.Run(tt.name, func(t *testing.T) { 64 base := NewBase( 65 tview.NewApplication(), 66 make(chan bool), 67 tview.NewPages(), 68 &cfg.Common{}, 69 ) 70 base.SetFocusChar(tt.focusChar) 71 72 actual := base.ContextualTitle(tt.defaultStr) 73 assert.Equal(t, tt.expected, actual) 74 }) 75 } 76 }