github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/text/internal/colltab/iter_test.go (about)

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