This commit is contained in:
parent
88d899cbbf
commit
ca49b44c73
@ -44,11 +44,11 @@ func isCtrl(char rune) bool {
|
|||||||
|
|
||||||
// Return the input code of a Ctrl-key chord.
|
// Return the input code of a Ctrl-key chord.
|
||||||
func ctrl(char rune) rune {
|
func ctrl(char rune) rune {
|
||||||
ch := char & 0x1f
|
if !isAscii(char) {
|
||||||
|
|
||||||
if !isCtrl(ch) {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ch := char & 0x1f
|
||||||
|
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
@ -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) {
|
func TestTruncateString(t *testing.T) {
|
||||||
firstString := "abcdefghijklmnopqrstuvwxyz"
|
firstString := "abcdefghijklmnopqrstuvwxyz"
|
||||||
truncated := truncateString(firstString, 13)
|
truncated := truncateString(firstString, 13)
|
||||||
|
Loading…
Reference in New Issue
Block a user