gen9.0.0_test.go 1.9 KB

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