github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/define_index_tables_test.go (about) 1 package lang 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/test/count" 7 ) 8 9 func TestCharToIndex(t *testing.T) { 10 lower := []byte{ 11 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 12 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 13 'u', 'v', 'w', 'x', 'y', 'z'} 14 upper := []byte{ 15 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 16 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 17 'U', 'V', 'W', 'X', 'Y', 'Z'} 18 19 count.Tests(t, 2) 20 21 test := func(chars []byte) { 22 for i, v := range chars { 23 if i != charToIndex(v) { 24 t.Errorf("'%s' shouldn't equal %d, expecting %d", string([]byte{v}), charToIndex(v), i) 25 } 26 } 27 } 28 29 test(lower) 30 test(upper) 31 }