github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/golang/text/secure/precis/tables_test.go (about) 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 "github.com/insionng/yougam/libraries/x/text/runes" 13 "github.com/insionng/yougam/libraries/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 func (tt *tableTest) run(t *testing.T) { 35 rangetable.Visit(tt.rangeTable, func(r rune) { 36 b := make([]byte, 4) 37 n := utf8.EncodeRune(b, r) 38 trieval, _ := dpTrie.lookup(b[:n]) 39 p := property(trieval) 40 if p != tt.prop && !exceptions.Contains(r) { 41 t.Fail() 42 } 43 }) 44 } 45 46 // Ensure that ceratain properties were generated correctly. 47 func TestTable(t *testing.T) { 48 tests := []tableTest{ 49 tableTest{ 50 rangetable.Merge( 51 unicode.Lt, unicode.Nl, unicode.No, // Other letter digits 52 unicode.Me, // Modifiers 53 unicode.Zs, // Spaces 54 unicode.So, // Symbols 55 unicode.Pi, unicode.Pf, // Punctuation 56 ), 57 freePVal | idDis, 58 }, 59 tableTest{ 60 rangetable.New(0x30000, 0x30101, 0xDFFFF), 61 unassigned, 62 }, 63 } 64 65 for _, test := range tests { 66 test.run(t) 67 } 68 }