104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
package char
|
|
|
|
import "testing"
|
|
|
|
type isA struct {
|
|
arg1 rune
|
|
expected bool
|
|
}
|
|
|
|
func TestIsAscii(t *testing.T) {
|
|
// (╯°□°)╯︵ ┻━┻
|
|
var isAsciiTest = []isA{
|
|
{'┻', false},
|
|
{'$', true},
|
|
{'︵', false},
|
|
{0x7f, true},
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsCtrl(t *testing.T) {
|
|
var isCtrlTest = []isA{
|
|
{0x78, false},
|
|
{0x7f, true},
|
|
{0x02, true},
|
|
{0x98, false},
|
|
{'a', false},
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCtrl(t *testing.T) {
|
|
type ctrlTest struct {
|
|
arg1, expected rune
|
|
}
|
|
|
|
var ctrlTests = []ctrlTest{
|
|
{'A', '\x01'},
|
|
{'B', '\x02'},
|
|
{'Z', '\x1a'},
|
|
{'#', 3},
|
|
{'┻', 0},
|
|
{'😿', 0},
|
|
}
|
|
|
|
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 TestIsSeparator(t *testing.T) {
|
|
for _, r := range ",.()+-/*=~%<>[] \t" {
|
|
if !IsSeparator(r) {
|
|
t.Errorf("Expected %q to be a syntax separator", r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsDigit(t *testing.T) {
|
|
var digitTests = []isA{
|
|
{'0', true},
|
|
{'1', true},
|
|
{'.', false},
|
|
{'A', false},
|
|
{'😿', false},
|
|
{'$', false},
|
|
}
|
|
|
|
for _, test := range digitTests {
|
|
if output := IsDigit(test.arg1); output != test.expected {
|
|
t.Errorf("Output '%v' not equal to expected '%v' for input %q", output, test.expected, test.arg1)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsNumeric(t *testing.T) {
|
|
var numericTests = []isA{
|
|
{'0', true},
|
|
{'1', true},
|
|
{'.', true},
|
|
{'A', false},
|
|
{'😿', false},
|
|
{'$', false},
|
|
}
|
|
|
|
for _, test := range numericTests {
|
|
if output := IsNumeric(test.arg1); output != test.expected {
|
|
t.Errorf("Output '%v' not equal to expected '%v' for input %q", output, test.expected, test.arg1)
|
|
}
|
|
}
|
|
}
|