diff --git a/editor/fn.go b/editor/fn.go index 9ab445f..c8a85a6 100644 --- a/editor/fn.go +++ b/editor/fn.go @@ -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 } \ No newline at end of file diff --git a/editor/fn_test.go b/editor/fn_test.go index 943d508..bf01b6e 100644 --- a/editor/fn_test.go +++ b/editor/fn_test.go @@ -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)