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