go-utf8/runelength_test.go

133 lines
1.5 KiB
Go
Raw Permalink Normal View History

2022-07-18 23:36:02 +00:00
package utf8
2018-07-02 18:03:47 +00:00
import (
"testing"
)
2022-07-19 01:48:37 +00:00
func TestRuneLength(t *testing.T) {
2018-07-02 18:03:47 +00:00
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,
},
2018-07-02 18:14:48 +00:00
{
Datum: '\u0000',
Expected: 1,
},
{
Datum: '\u0001',
Expected: 1,
},
{
Datum: '\u007e',
Expected: 1,
},
{
Datum: '\u007f',
Expected: 1,
},
{
Datum: '\u0080',
Expected: 2,
},
{
Datum: '\u0081',
Expected: 2,
},
{
Datum: '\u07fe',
Expected: 2,
},
{
Datum: '\u07ff',
Expected: 2,
},
{
Datum: '\u0800',
Expected: 3,
},
{
Datum: '\u0801',
Expected: 3,
},
{
Datum: '\ufffe',
Expected: 3,
},
{
Datum: '\uffff',
Expected: 3,
},
{
Datum: '\U00010000',
Expected: 4,
},
{
Datum: '\U00010001',
Expected: 4,
},
{
Datum: '\U0010fffe',
Expected: 4,
},
{
Datum: '\U0010ffff',
Expected: 4,
},
2018-07-02 18:03:47 +00:00
}
for testNumber, test := range tests {
2022-07-19 01:48:37 +00:00
actual := RuneLength(test.Datum)
2018-07-02 18:03:47 +00:00
if expected := test.Expected; expected != actual {
t.Errorf("For test #%d, expected %d, but actually got %d.", testNumber, expected, actual)
continue
}
}
}