tables_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 bidi
  5. import (
  6. "testing"
  7. "golang.org/x/text/internal/gen"
  8. "golang.org/x/text/internal/testtext"
  9. "golang.org/x/text/internal/ucd"
  10. )
  11. var labels = []string{
  12. AL: "AL",
  13. AN: "AN",
  14. B: "B",
  15. BN: "BN",
  16. CS: "CS",
  17. EN: "EN",
  18. ES: "ES",
  19. ET: "ET",
  20. L: "L",
  21. NSM: "NSM",
  22. ON: "ON",
  23. R: "R",
  24. S: "S",
  25. WS: "WS",
  26. LRO: "LRO",
  27. RLO: "RLO",
  28. LRE: "LRE",
  29. RLE: "RLE",
  30. PDF: "PDF",
  31. LRI: "LRI",
  32. RLI: "RLI",
  33. FSI: "FSI",
  34. PDI: "PDI",
  35. }
  36. func TestTables(t *testing.T) {
  37. testtext.SkipIfNotLong(t)
  38. ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) {
  39. r1 := p.Rune(0)
  40. want := p.Rune(1)
  41. e, _ := LookupRune(r1)
  42. if got := e.reverseBracket(r1); got != want {
  43. t.Errorf("Reverse(%U) = %U; want %U", r1, got, want)
  44. }
  45. })
  46. done := map[rune]bool{}
  47. test := func(name string, r rune, want string) {
  48. str := string(r)
  49. e, _ := LookupString(str)
  50. if got := labels[e.Class()]; got != want {
  51. t.Errorf("%s:%U: got %s; want %s", name, r, got, want)
  52. }
  53. if e2, sz := LookupRune(r); e != e2 || sz != len(str) {
  54. t.Errorf("LookupRune(%U) = %v, %d; want %v, %d", r, e2, e, sz, len(str))
  55. }
  56. if e2, sz := Lookup([]byte(str)); e != e2 || sz != len(str) {
  57. t.Errorf("Lookup(%U) = %v, %d; want %v, %d", r, e2, e, sz, len(str))
  58. }
  59. done[r] = true
  60. }
  61. // Insert the derived BiDi properties.
  62. ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) {
  63. r := p.Rune(0)
  64. test("derived", r, p.String(1))
  65. })
  66. visitDefaults(func(r rune, c Class) {
  67. if !done[r] {
  68. test("default", r, labels[c])
  69. }
  70. })
  71. }