More tests
Some checks failed
timw4mail/gilo/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2021-03-30 20:22:11 -04:00
parent 88d899cbbf
commit ca49b44c73
2 changed files with 24 additions and 3 deletions

View File

@ -44,11 +44,11 @@ func isCtrl(char rune) bool {
// Return the input code of a Ctrl-key chord.
func ctrl(char rune) rune {
ch := char & 0x1f
if !isCtrl(ch) {
if !isAscii(char) {
return 0
}
ch := char & 0x1f
return ch
}

View File

@ -41,6 +41,27 @@ func TestIsCtrl(t *testing.T) {
}
}
type ctrlTest struct {
arg1, expected rune
}
var ctrlTests = []ctrlTest {
{'A', '\x01'},
{'B', '\x02'},
{'Z', '\x1a'},
{'#', 3},
{'┻', 0},
{'😿', 0},
}
func TestCtrl(t *testing.T) {
for _, test := range ctrlTests {
if output := ctrl(test.arg1); output != test.expected {
t.Errorf("Output %v not equal to expected %v for input %q", output, test.expected, test.arg1)
}
}
}
func TestTruncateString(t *testing.T) {
firstString := "abcdefghijklmnopqrstuvwxyz"
truncated := truncateString(firstString, 13)