62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
|
package key
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
type isRune struct {
|
||
|
arg1 rune
|
||
|
expected bool
|
||
|
}
|
||
|
|
||
|
// (╯°□°)╯︵ ┻━┻
|
||
|
var isAsciiTest = []isRune{
|
||
|
{'┻', false},
|
||
|
{'$', true},
|
||
|
{'︵', false},
|
||
|
{0x7f, true},
|
||
|
}
|
||
|
|
||
|
func TestIsAscii(t *testing.T) {
|
||
|
for _, test := range isAsciiTest {
|
||
|
if output := isAscii(test.arg1); output != test.expected {
|
||
|
t.Errorf("Output %v not equal to expected %v for input %q", output, test.expected, test.arg1)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var isCtrlTest = []isRune{
|
||
|
{0x78, false},
|
||
|
{0x7f, true},
|
||
|
{0x02, true},
|
||
|
{0x98, false},
|
||
|
{'a', false},
|
||
|
}
|
||
|
|
||
|
func TestIsCtrl(t *testing.T) {
|
||
|
for _, test := range isCtrlTest {
|
||
|
if output := IsCtrl(test.arg1); output != test.expected {
|
||
|
t.Errorf("Output %v not equal to expected %v for input %q", output, test.expected, test.arg1)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|