-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jisx0208_test.go
68 lines (62 loc) · 1.59 KB
/
jisx0208_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jisx0208
import (
"fmt"
"testing"
"unicode"
)
type range16 unicode.Range16
func (r range16) String() string {
return fmt.Sprintf("{Lo:0x%04X, Hi:0x%04X, Stride:%d}", r.Lo, r.Hi, r.Stride)
}
type range32 unicode.Range32
func (r range32) String() string {
return fmt.Sprintf("{Lo:0x%0X, Hi:0x%0X, Stride:%d}", r.Lo, r.Hi, r.Stride)
}
func TestExtendedCharacterValidation(t *testing.T) {
// R16
for i, v := range RangeTable.R16 {
// stride check
if want, got := uint16(1), v.Stride; want != got {
t.Errorf("stride want %d, got %d", want, got)
}
// range check
if v.Lo > v.Hi {
t.Errorf("range error, %v", range16(v))
}
// overlap check
if i != 0 {
vv := RangeTable.R16[i-1]
if vv.Hi > v.Lo {
t.Errorf("overlap %v, %v", range16(vv), range16(v))
}
}
// boundary check
if !unicode.Is(RangeTable, rune(v.Lo)) {
t.Errorf("boundary value error (lo), %v, 0x%04X", range16(v), v.Lo)
}
if !unicode.Is(RangeTable, rune(v.Hi)) {
t.Errorf("boundary value error (hi), %v, 0x%04X", range16(v), v.Hi)
}
}
// R32
for i, v := range RangeTable.R32 {
// stride check
if want, got := uint32(1), v.Stride; want != got {
t.Errorf("stride want %d, got %d", want, got)
}
// overlap check
if i != 0 {
vv := RangeTable.R32[i-1]
if vv.Hi > v.Lo {
t.Errorf("overlap %v, %v", range32(vv), range32(v))
}
}
// boundary check
if !unicode.Is(RangeTable, rune(v.Lo)) {
t.Errorf("boundary value error, %v, 0x%0X", range32(v), v.Lo)
}
if !unicode.Is(RangeTable, rune(v.Hi)) {
t.Errorf("boundary value error, %v, 0x%0X", range32(v), v.Hi)
}
}
}