go-utf8/len_test.go

57 lines
708 B
Go
Raw Normal View History

2018-07-02 18:03:47 +00:00
package utf8s
import (
"testing"
)
func TestLen(t *testing.T) {
tests := []struct{
Datum rune
Expected int
}{
{
Datum: 'A',
Expected: 1,
},
{
Datum: 'r',
Expected: 1,
},
{
Datum: '¡',
Expected: 2,
},
{
Datum: '۵',
Expected: 2,
},
{
Datum: '‱',
Expected: 3,
},
{
Datum: '≡',
Expected: 3,
},
{
Datum: '𐏕',
Expected: 4,
},
{
Datum: '🙂',
Expected: 4,
},
}
for testNumber, test := range tests {
actual := Len(test.Datum)
if expected := test.Expected; expected != actual {
t.Errorf("For test #%d, expected %d, but actually got %d.", testNumber, expected, actual)
continue
}
}
}