From ca49b44c73e0e9ce6b789eeb77e9ec5ec3190a18 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 30 Mar 2021 20:22:11 -0400 Subject: [PATCH] More tests --- editor/fn.go | 6 +++--- editor/fn_test.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) 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)