| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package precis |
| 6 |
|
| 7 |
import ( |
| 8 |
"testing" |
| 9 |
"unicode" |
| 10 |
"unicode/utf8" |
| 11 |
|
| 12 |
"golang.org/x/text/runes" |
| 13 |
"golang.org/x/text/unicode/rangetable" |
| 14 |
) |
| 15 |
|
| 16 |
type tableTest struct { |
| 17 |
rangeTable *unicode.RangeTable |
| 18 |
prop property |
| 19 |
} |
| 20 |
|
| 21 |
var exceptions = runes.Predicate(func(r rune) bool { |
| 22 |
switch uint32(r) { |
| 23 |
case 0x00DF, 0x03C2, 0x06FD, 0x06FE, 0x0F0B, 0x3007, 0x00B7, 0x0375, 0x05F3, |
| 24 |
0x05F4, 0x30FB, 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, |
| 25 |
0x0667, 0x0668, 0x0669, 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, |
| 26 |
0x06F6, 0x06F7, 0x06F8, 0x06F9, 0x0640, 0x07FA, 0x302E, 0x302F, 0x3031, |
| 27 |
0x3032, 0x3033, 0x3034, 0x3035, 0x303B: |
| 28 |
return true |
| 29 |
default: |
| 30 |
return false |
| 31 |
} |
| 32 |
}) |
| 33 |
|
| 34 |
// Ensure that certain properties were generated correctly. |
| 35 |
func TestTable(t *testing.T) { |
| 36 |
tests := []tableTest{ |
| 37 |
tableTest{ |
| 38 |
rangetable.Merge( |
| 39 |
unicode.Lt, unicode.Nl, unicode.No, // Other letter digits |
| 40 |
unicode.Me, // Modifiers |
| 41 |
unicode.Zs, // Spaces |
| 42 |
unicode.So, // Symbols |
| 43 |
unicode.Pi, unicode.Pf, // Punctuation |
| 44 |
), |
| 45 |
idDisOrFreePVal, |
| 46 |
}, |
| 47 |
tableTest{ |
| 48 |
rangetable.New(0xA0000, 0xA0101, 0xDFFFF), |
| 49 |
unassigned, |
| 50 |
}, |
| 51 |
} |
| 52 |
|
| 53 |
assigned := rangetable.Assigned(UnicodeVersion) |
| 54 |
|
| 55 |
for _, test := range tests { |
| 56 |
rangetable.Visit(test.rangeTable, func(r rune) { |
| 57 |
if !unicode.In(r, assigned) { |
| 58 |
return |
| 59 |
} |
| 60 |
b := make([]byte, 4) |
| 61 |
n := utf8.EncodeRune(b, r) |
| 62 |
trieval, _ := dpTrie.lookup(b[:n]) |
| 63 |
p := entry(trieval).property() |
| 64 |
if p != test.prop && !exceptions.Contains(r) { |
| 65 |
t.Errorf("%U: got %+x; want %+x", r, test.prop, p) |
| 66 |
} |
| 67 |
}) |
| 68 |
} |
| 69 |
} |