Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

70 linhas
1.7 KiB

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