gen9.0.0_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2016 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. // +build !go1.10
  5. package idna
  6. import (
  7. "testing"
  8. "unicode"
  9. "golang.org/x/text/internal/gen"
  10. "golang.org/x/text/internal/testtext"
  11. "golang.org/x/text/internal/ucd"
  12. )
  13. func TestTables(t *testing.T) {
  14. testtext.SkipIfNotLong(t)
  15. lookup := func(r rune) info {
  16. v, _ := trie.lookupString(string(r))
  17. return info(v)
  18. }
  19. ucd.Parse(gen.OpenUnicodeFile("idna", "", "IdnaMappingTable.txt"), func(p *ucd.Parser) {
  20. r := p.Rune(0)
  21. x := lookup(r)
  22. if got, want := x.category(), catFromEntry(p); got != want {
  23. t.Errorf("%U:category: got %x; want %x", r, got, want)
  24. }
  25. mapped := false
  26. switch p.String(1) {
  27. case "mapped", "disallowed_STD3_mapped", "deviation":
  28. mapped = true
  29. }
  30. if x.isMapped() != mapped {
  31. t.Errorf("%U:isMapped: got %v; want %v", r, x.isMapped(), mapped)
  32. }
  33. if !mapped {
  34. return
  35. }
  36. want := string(p.Runes(2))
  37. got := string(x.appendMapping(nil, string(r)))
  38. if got != want {
  39. t.Errorf("%U:mapping: got %+q; want %+q", r, got, want)
  40. }
  41. if x.isMapped() {
  42. return
  43. }
  44. wantMark := unicode.In(r, unicode.Mark)
  45. gotMark := x.isModifier()
  46. if gotMark != wantMark {
  47. t.Errorf("IsMark(%U) = %v; want %v", r, gotMark, wantMark)
  48. }
  49. })
  50. ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
  51. r := p.Rune(0)
  52. x := lookup(r)
  53. got := x.isViramaModifier()
  54. const cccVirama = 9
  55. want := p.Int(ucd.CanonicalCombiningClass) == cccVirama
  56. if got != want {
  57. t.Errorf("IsVirama(%U) = %v; want %v", r, got, want)
  58. }
  59. })
  60. ucd.Parse(gen.OpenUCDFile("extracted/DerivedJoiningType.txt"), func(p *ucd.Parser) {
  61. r := p.Rune(0)
  62. x := lookup(r)
  63. if x.isMapped() {
  64. return
  65. }
  66. got := x.joinType()
  67. want := joinType[p.String(1)]
  68. if got != want {
  69. t.Errorf("JoinType(%U) = %x; want %x", r, got, want)
  70. }
  71. })
  72. }