You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.1 KiB

  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. rtl := false
  60. switch p.String(ucd.BidiClass) {
  61. case "R", "AL", "AN":
  62. rtl = true
  63. }
  64. if got := x.isBidi("A"); got != rtl && !x.isMapped() {
  65. t.Errorf("IsBidi(%U) = %v; want %v", r, got, rtl)
  66. }
  67. })
  68. ucd.Parse(gen.OpenUCDFile("extracted/DerivedJoiningType.txt"), func(p *ucd.Parser) {
  69. r := p.Rune(0)
  70. x := lookup(r)
  71. if x.isMapped() {
  72. return
  73. }
  74. got := x.joinType()
  75. want := joinType[p.String(1)]
  76. if got != want {
  77. t.Errorf("JoinType(%U) = %x; want %x", r, got, want)
  78. }
  79. })
  80. }