iter_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 colltab
  5. import (
  6. "testing"
  7. )
  8. func TestDoNorm(t *testing.T) {
  9. const div = -1 // The insertion point of the next block.
  10. tests := []struct {
  11. in, out []int
  12. }{{
  13. in: []int{4, div, 3},
  14. out: []int{3, 4},
  15. }, {
  16. in: []int{4, div, 3, 3, 3},
  17. out: []int{3, 3, 3, 4},
  18. }, {
  19. in: []int{0, 4, div, 3},
  20. out: []int{0, 3, 4},
  21. }, {
  22. in: []int{0, 0, 4, 5, div, 3, 3},
  23. out: []int{0, 0, 3, 3, 4, 5},
  24. }, {
  25. in: []int{0, 0, 1, 4, 5, div, 3, 3},
  26. out: []int{0, 0, 1, 3, 3, 4, 5},
  27. }, {
  28. in: []int{0, 0, 1, 4, 5, div, 4, 4},
  29. out: []int{0, 0, 1, 4, 4, 4, 5},
  30. },
  31. }
  32. for j, tt := range tests {
  33. i := Iter{}
  34. var w, p int
  35. for k, cc := range tt.in {
  36. if cc == div {
  37. w = 100
  38. p = k
  39. continue
  40. }
  41. i.Elems = append(i.Elems, makeCE([]int{w, defaultSecondary, 2, cc}))
  42. }
  43. i.doNorm(p, i.Elems[p].CCC())
  44. if len(i.Elems) != len(tt.out) {
  45. t.Errorf("%d: length was %d; want %d", j, len(i.Elems), len(tt.out))
  46. }
  47. prevCCC := uint8(0)
  48. for k, ce := range i.Elems {
  49. if int(ce.CCC()) != tt.out[k] {
  50. t.Errorf("%d:%d: unexpected CCC. Was %d; want %d", j, k, ce.CCC(), tt.out[k])
  51. }
  52. if k > 0 && ce.CCC() == prevCCC && i.Elems[k-1].Primary() > ce.Primary() {
  53. t.Errorf("%d:%d: normalization crossed across CCC boundary.", j, k)
  54. }
  55. }
  56. }
  57. // Combining rune overflow is tested in search/pattern_test.go.
  58. }