2021-04-01 16:17:13 -04:00
|
|
|
package key
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
type isRune struct {
|
2021-04-01 16:47:32 -04:00
|
|
|
arg1 rune
|
2021-04-01 16:17:13 -04:00
|
|
|
expected bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// (╯°□°)╯︵ ┻━┻
|
|
|
|
var isAsciiTest = []isRune{
|
|
|
|
{'┻', false},
|
|
|
|
{'$', true},
|
|
|
|
{'︵', false},
|
|
|
|
{0x7f, true},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsAscii(t *testing.T) {
|
|
|
|
for _, test := range isAsciiTest {
|
2021-04-02 19:24:20 -04:00
|
|
|
if output := IsAscii(test.arg1); output != test.expected {
|
2021-04-01 16:17:13 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-04 12:50:21 -04:00
|
|
|
|
|
|
|
func TestIsSeparator(t *testing.T) {
|
|
|
|
separators := ",.()+-/*=~%<>[] \t"
|
|
|
|
for _, r := range separators {
|
|
|
|
if !IsSeparator(r) {
|
|
|
|
t.Errorf("Expected %q to be a syntax separator", r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|