rangetable_test.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package rangetable
  2. import (
  3. "reflect"
  4. "testing"
  5. "unicode"
  6. )
  7. var (
  8. empty = &unicode.RangeTable{}
  9. many = &unicode.RangeTable{
  10. R16: []unicode.Range16{{0, 0xffff, 5}},
  11. R32: []unicode.Range32{{0x10004, 0x10009, 5}},
  12. LatinOffset: 0,
  13. }
  14. )
  15. func TestVisit(t *testing.T) {
  16. Visit(empty, func(got rune) {
  17. t.Error("call from empty RangeTable")
  18. })
  19. var want rune
  20. Visit(many, func(got rune) {
  21. if got != want {
  22. t.Errorf("got %U; want %U", got, want)
  23. }
  24. want += 5
  25. })
  26. if want -= 5; want != 0x10009 {
  27. t.Errorf("last run was %U; want U+10009", want)
  28. }
  29. }
  30. func TestNew(t *testing.T) {
  31. for i, rt := range []*unicode.RangeTable{
  32. empty,
  33. unicode.Co,
  34. unicode.Letter,
  35. unicode.ASCII_Hex_Digit,
  36. many,
  37. maxRuneTable,
  38. } {
  39. var got, want []rune
  40. Visit(rt, func(r rune) {
  41. want = append(want, r)
  42. })
  43. Visit(New(want...), func(r rune) {
  44. got = append(got, r)
  45. })
  46. if !reflect.DeepEqual(got, want) {
  47. t.Errorf("%d:\ngot %v;\nwant %v", i, got, want)
  48. }
  49. }
  50. }