-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from noborus/help-test
Added test for keybind help
- Loading branch information
Showing
4 changed files
with
181 additions
and
101 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
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
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
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,64 @@ | ||
package oviewer | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gdamore/tcell/v2" | ||
) | ||
|
||
func Test_defaultKeyBinds(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
}{ | ||
{ | ||
name: "KeyBind", | ||
}, | ||
} | ||
tcellNewScreen = fakeScreen | ||
defer func() { | ||
tcellNewScreen = tcell.NewScreen | ||
}() | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
root, err := NewRoot(bytes.NewBufferString("test")) | ||
if err != nil { | ||
t.Fatal("NewRoot failed: ", err) | ||
} | ||
hm := root.handlers() | ||
kb := defaultKeyBinds() | ||
if len(hm) != len(kb) { | ||
t.Errorf("number of KeyBind = %v, want %v", len(hm), len(kb)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestKeyBind_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
k KeyBind | ||
}{ | ||
{ | ||
name: "KeyBind String", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
kb := defaultKeyBinds() | ||
kbStr := kb.String() | ||
count := 0 | ||
s := bufio.NewScanner(bytes.NewBufferString(kbStr)) | ||
for s.Scan() { | ||
if strings.HasPrefix(s.Text(), " ") { | ||
count++ | ||
} | ||
} | ||
if count != len(kb) { | ||
t.Errorf("number of KeyBind String = %v, want %v", count, len(kb)) | ||
} | ||
}) | ||
} | ||
} |