mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor cleanup: remove unused,non-go and test files
This commit is contained in:
121
vendor/golang.org/x/text/internal/colltab/collate_test.go
generated
vendored
121
vendor/golang.org/x/text/internal/colltab/collate_test.go
generated
vendored
@ -1,121 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab_test
|
||||
|
||||
// This file contains tests which need to import package collate, which causes
|
||||
// an import cycle when done within package colltab itself.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/text/collate"
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/unicode/rangetable"
|
||||
)
|
||||
|
||||
// assigned is used to only test runes that are inside the scope of the Unicode
|
||||
// version used to generation the collation table.
|
||||
var assigned = rangetable.Assigned(collate.UnicodeVersion)
|
||||
|
||||
func TestNonDigits(t *testing.T) {
|
||||
c := collate.New(language.English, collate.Loose, collate.Numeric)
|
||||
|
||||
// Verify that all non-digit numbers sort outside of the number range.
|
||||
for r, hi := rune(unicode.N.R16[0].Lo), rune(unicode.N.R32[0].Hi); r <= hi; r++ {
|
||||
if unicode.In(r, unicode.Nd) || !unicode.In(r, assigned) {
|
||||
continue
|
||||
}
|
||||
if a := string(r); c.CompareString(a, "0") != -1 && c.CompareString(a, "999999") != 1 {
|
||||
t.Errorf("%+q non-digit number is collated as digit", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNumericCompare(t *testing.T) {
|
||||
c := collate.New(language.English, collate.Loose, collate.Numeric)
|
||||
|
||||
// Iterate over all digits.
|
||||
for _, r16 := range unicode.Nd.R16 {
|
||||
testDigitCompare(t, c, rune(r16.Lo), rune(r16.Hi))
|
||||
}
|
||||
for _, r32 := range unicode.Nd.R32 {
|
||||
testDigitCompare(t, c, rune(r32.Lo), rune(r32.Hi))
|
||||
}
|
||||
}
|
||||
|
||||
func testDigitCompare(t *testing.T, c *collate.Collator, zero, nine rune) {
|
||||
if !unicode.In(zero, assigned) {
|
||||
return
|
||||
}
|
||||
n := int(nine - zero + 1)
|
||||
if n%10 != 0 {
|
||||
t.Fatalf("len([%+q, %+q]) = %d; want a multiple of 10", zero, nine, n)
|
||||
}
|
||||
for _, tt := range []struct {
|
||||
prefix string
|
||||
b [11]string
|
||||
}{
|
||||
{
|
||||
prefix: "",
|
||||
b: [11]string{
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
},
|
||||
},
|
||||
{
|
||||
prefix: "1",
|
||||
b: [11]string{
|
||||
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
|
||||
},
|
||||
},
|
||||
{
|
||||
prefix: "0",
|
||||
b: [11]string{
|
||||
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
|
||||
},
|
||||
},
|
||||
{
|
||||
prefix: "00",
|
||||
b: [11]string{
|
||||
"000", "001", "002", "003", "004", "005", "006", "007", "008", "009", "010",
|
||||
},
|
||||
},
|
||||
{
|
||||
prefix: "9",
|
||||
b: [11]string{
|
||||
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100",
|
||||
},
|
||||
},
|
||||
} {
|
||||
for k := 0; k <= n; k++ {
|
||||
i := k % 10
|
||||
a := tt.prefix + string(zero+rune(i))
|
||||
for j, b := range tt.b {
|
||||
want := 0
|
||||
switch {
|
||||
case i < j:
|
||||
want = -1
|
||||
case i > j:
|
||||
want = 1
|
||||
}
|
||||
got := c.CompareString(a, b)
|
||||
if got != want {
|
||||
t.Errorf("Compare(%+q, %+q) = %d; want %d", a, b, got, want)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNumericWeighter(b *testing.B) {
|
||||
c := collate.New(language.English, collate.Numeric)
|
||||
input := bytes.Repeat([]byte("Testing, testing 123..."), 100)
|
||||
b.SetBytes(int64(2 * len(input)))
|
||||
for i := 0; i < b.N; i++ {
|
||||
c.Compare(input, input)
|
||||
}
|
||||
}
|
183
vendor/golang.org/x/text/internal/colltab/collelem_test.go
generated
vendored
183
vendor/golang.org/x/text/internal/colltab/collelem_test.go
generated
vendored
@ -1,183 +0,0 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func (e Elem) String() string {
|
||||
q := ""
|
||||
if v := e.Quaternary(); v == MaxQuaternary {
|
||||
q = "max"
|
||||
} else {
|
||||
q = fmt.Sprint(v)
|
||||
}
|
||||
return fmt.Sprintf("[%d, %d, %d, %s]",
|
||||
e.Primary(),
|
||||
e.Secondary(),
|
||||
e.Tertiary(),
|
||||
q)
|
||||
}
|
||||
|
||||
type ceTest struct {
|
||||
f func(inout []int) (Elem, ceType)
|
||||
arg []int
|
||||
}
|
||||
|
||||
func makeCE(weights []int) Elem {
|
||||
ce, _ := MakeElem(weights[0], weights[1], weights[2], uint8(weights[3]))
|
||||
return ce
|
||||
}
|
||||
|
||||
var defaultValues = []int{0, defaultSecondary, defaultTertiary, 0}
|
||||
|
||||
func e(w ...int) Elem {
|
||||
return makeCE(append(w, defaultValues[len(w):]...))
|
||||
}
|
||||
|
||||
func makeContractIndex(index, n, offset int) Elem {
|
||||
const (
|
||||
contractID = 0xC0000000
|
||||
maxNBits = 4
|
||||
maxTrieIndexBits = 12
|
||||
maxContractOffsetBits = 13
|
||||
)
|
||||
ce := Elem(contractID)
|
||||
ce += Elem(offset << (maxNBits + maxTrieIndexBits))
|
||||
ce += Elem(index << maxNBits)
|
||||
ce += Elem(n)
|
||||
return ce
|
||||
}
|
||||
|
||||
func makeExpandIndex(index int) Elem {
|
||||
const expandID = 0xE0000000
|
||||
return expandID + Elem(index)
|
||||
}
|
||||
|
||||
func makeDecompose(t1, t2 int) Elem {
|
||||
const decompID = 0xF0000000
|
||||
return Elem(t2<<8+t1) + decompID
|
||||
}
|
||||
|
||||
func normalCE(inout []int) (ce Elem, t ceType) {
|
||||
ce = makeCE(inout)
|
||||
inout[0] = ce.Primary()
|
||||
inout[1] = ce.Secondary()
|
||||
inout[2] = int(ce.Tertiary())
|
||||
inout[3] = int(ce.CCC())
|
||||
return ce, ceNormal
|
||||
}
|
||||
|
||||
func expandCE(inout []int) (ce Elem, t ceType) {
|
||||
ce = makeExpandIndex(inout[0])
|
||||
inout[0] = splitExpandIndex(ce)
|
||||
return ce, ceExpansionIndex
|
||||
}
|
||||
|
||||
func contractCE(inout []int) (ce Elem, t ceType) {
|
||||
ce = makeContractIndex(inout[0], inout[1], inout[2])
|
||||
i, n, o := splitContractIndex(ce)
|
||||
inout[0], inout[1], inout[2] = i, n, o
|
||||
return ce, ceContractionIndex
|
||||
}
|
||||
|
||||
func decompCE(inout []int) (ce Elem, t ceType) {
|
||||
ce = makeDecompose(inout[0], inout[1])
|
||||
t1, t2 := splitDecompose(ce)
|
||||
inout[0], inout[1] = int(t1), int(t2)
|
||||
return ce, ceDecompose
|
||||
}
|
||||
|
||||
var ceTests = []ceTest{
|
||||
{normalCE, []int{0, 0, 0, 0}},
|
||||
{normalCE, []int{0, 30, 3, 0}},
|
||||
{normalCE, []int{0, 30, 3, 0xFF}},
|
||||
{normalCE, []int{100, defaultSecondary, defaultTertiary, 0}},
|
||||
{normalCE, []int{100, defaultSecondary, defaultTertiary, 0xFF}},
|
||||
{normalCE, []int{100, defaultSecondary, 3, 0}},
|
||||
{normalCE, []int{0x123, defaultSecondary, 8, 0xFF}},
|
||||
|
||||
{contractCE, []int{0, 0, 0}},
|
||||
{contractCE, []int{1, 1, 1}},
|
||||
{contractCE, []int{1, (1 << maxNBits) - 1, 1}},
|
||||
{contractCE, []int{(1 << maxTrieIndexBits) - 1, 1, 1}},
|
||||
{contractCE, []int{1, 1, (1 << maxContractOffsetBits) - 1}},
|
||||
|
||||
{expandCE, []int{0}},
|
||||
{expandCE, []int{5}},
|
||||
{expandCE, []int{(1 << maxExpandIndexBits) - 1}},
|
||||
|
||||
{decompCE, []int{0, 0}},
|
||||
{decompCE, []int{1, 1}},
|
||||
{decompCE, []int{0x1F, 0x1F}},
|
||||
}
|
||||
|
||||
func TestColElem(t *testing.T) {
|
||||
for i, tt := range ceTests {
|
||||
inout := make([]int, len(tt.arg))
|
||||
copy(inout, tt.arg)
|
||||
ce, typ := tt.f(inout)
|
||||
if ce.ctype() != typ {
|
||||
t.Errorf("%d: type is %d; want %d (ColElem: %X)", i, ce.ctype(), typ, ce)
|
||||
}
|
||||
for j, a := range tt.arg {
|
||||
if inout[j] != a {
|
||||
t.Errorf("%d: argument %d is %X; want %X (ColElem: %X)", i, j, inout[j], a, ce)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type implicitTest struct {
|
||||
r rune
|
||||
p int
|
||||
}
|
||||
|
||||
var implicitTests = []implicitTest{
|
||||
{0x33FF, 0x533FF},
|
||||
{0x3400, 0x23400},
|
||||
{0x4DC0, 0x54DC0},
|
||||
{0x4DFF, 0x54DFF},
|
||||
{0x4E00, 0x14E00},
|
||||
{0x9FCB, 0x19FCB},
|
||||
{0xA000, 0x5A000},
|
||||
{0xF8FF, 0x5F8FF},
|
||||
{0xF900, 0x1F900},
|
||||
{0xFA23, 0x1FA23},
|
||||
{0xFAD9, 0x1FAD9},
|
||||
{0xFB00, 0x5FB00},
|
||||
{0x20000, 0x40000},
|
||||
{0x2B81C, 0x4B81C},
|
||||
{unicode.MaxRune, 0x15FFFF}, // maximum primary value
|
||||
}
|
||||
|
||||
func TestImplicit(t *testing.T) {
|
||||
for _, tt := range implicitTests {
|
||||
if p := implicitPrimary(tt.r); p != tt.p {
|
||||
t.Errorf("%U: was %X; want %X", tt.r, p, tt.p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTertiary(t *testing.T) {
|
||||
tests := []struct {
|
||||
in, out Elem
|
||||
t uint8
|
||||
}{
|
||||
{0x4000FE20, 0x0000FE8A, 0x0A},
|
||||
{0x4000FE21, 0x0000FEAA, 0x0A},
|
||||
{0x0000FE8B, 0x0000FE83, 0x03},
|
||||
{0x82FF0188, 0x9BFF0188, 0x1B},
|
||||
{0xAFF0CC02, 0xAFF0CC1B, 0x1B},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
if out := tt.in.updateTertiary(tt.t); out != tt.out {
|
||||
t.Errorf("%d: was %X; want %X", i, out, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
64
vendor/golang.org/x/text/internal/colltab/colltab_test.go
generated
vendored
64
vendor/golang.org/x/text/internal/colltab/colltab_test.go
generated
vendored
@ -1,64 +0,0 @@
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func TestMatchLang(t *testing.T) {
|
||||
tags := []language.Tag{
|
||||
0: language.Und,
|
||||
1: language.MustParse("bs"),
|
||||
2: language.German,
|
||||
3: language.English,
|
||||
4: language.AmericanEnglish,
|
||||
5: language.MustParse("en-US-u-va-posix"),
|
||||
6: language.Portuguese,
|
||||
7: language.Serbian,
|
||||
8: language.MustParse("sr-Latn"),
|
||||
9: language.Chinese,
|
||||
10: language.MustParse("zh-u-co-stroke"),
|
||||
11: language.MustParse("zh-Hant-u-co-pinyin"),
|
||||
12: language.TraditionalChinese,
|
||||
}
|
||||
for i, tc := range []struct {
|
||||
x int
|
||||
t language.Tag
|
||||
}{
|
||||
{0, language.Und},
|
||||
{0, language.Persian}, // Default to first element when no match.
|
||||
{3, language.English},
|
||||
{4, language.AmericanEnglish},
|
||||
{5, language.MustParse("en-US-u-va-posix")}, // Ext. variant match.
|
||||
{4, language.MustParse("en-US-u-va-noposix")}, // Ext. variant mismatch.
|
||||
{3, language.MustParse("en-UK-u-va-noposix")}, // Ext. variant mismatch.
|
||||
{7, language.Serbian},
|
||||
{0, language.Croatian}, // Don't match to close language!
|
||||
{0, language.MustParse("gsw")}, // Don't match to close language!
|
||||
{1, language.MustParse("bs-Cyrl")}, // Odd, but correct.
|
||||
{1, language.MustParse("bs-Latn")}, // Estimated script drops.
|
||||
{8, language.MustParse("sr-Latn")},
|
||||
{9, language.Chinese},
|
||||
{9, language.SimplifiedChinese},
|
||||
{12, language.TraditionalChinese},
|
||||
{11, language.MustParse("zh-Hant-u-co-pinyin")},
|
||||
// TODO: should this be 12? Either inherited value (10) or default is
|
||||
// fine in this case, though. Other locales are not affected.
|
||||
{10, language.MustParse("zh-Hant-u-co-stroke")},
|
||||
// There is no "phonebk" sorting order for zh-Hant, so use default.
|
||||
{12, language.MustParse("zh-Hant-u-co-phonebk")},
|
||||
{10, language.MustParse("zh-u-co-stroke")},
|
||||
{12, language.MustParse("und-TW")}, // Infer script and language.
|
||||
{12, language.MustParse("und-HK")}, // Infer script and language.
|
||||
{6, language.MustParse("und-BR")}, // Infer script and language.
|
||||
{6, language.MustParse("und-PT")}, // Infer script and language.
|
||||
{2, language.MustParse("und-Latn-DE")}, // Infer language.
|
||||
{0, language.MustParse("und-Jpan-BR")}, // Infers "ja", so no match.
|
||||
{0, language.MustParse("zu")}, // No match past index.
|
||||
} {
|
||||
if x := MatchLang(tc.t, tags); x != tc.x {
|
||||
t.Errorf("%d: MatchLang(%q, tags) = %d; want %d", i, tc.t, x, tc.x)
|
||||
}
|
||||
}
|
||||
}
|
131
vendor/golang.org/x/text/internal/colltab/contract_test.go
generated
vendored
131
vendor/golang.org/x/text/internal/colltab/contract_test.go
generated
vendored
@ -1,131 +0,0 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type lookupStrings struct {
|
||||
str string
|
||||
offset int
|
||||
n int // bytes consumed from input
|
||||
}
|
||||
|
||||
type LookupTest struct {
|
||||
lookup []lookupStrings
|
||||
n int
|
||||
tries ContractTrieSet
|
||||
}
|
||||
|
||||
var lookupTests = []LookupTest{{
|
||||
[]lookupStrings{
|
||||
{"abc", 1, 3},
|
||||
{"a", 0, 0},
|
||||
{"b", 0, 0},
|
||||
{"c", 0, 0},
|
||||
{"d", 0, 0},
|
||||
},
|
||||
1,
|
||||
ContractTrieSet{
|
||||
{'a', 0, 1, 0xFF},
|
||||
{'b', 0, 1, 0xFF},
|
||||
{'c', 'c', 0, 1},
|
||||
},
|
||||
}, {
|
||||
[]lookupStrings{
|
||||
{"abc", 1, 3},
|
||||
{"abd", 2, 3},
|
||||
{"abe", 3, 3},
|
||||
{"a", 0, 0},
|
||||
{"ab", 0, 0},
|
||||
{"d", 0, 0},
|
||||
{"f", 0, 0},
|
||||
},
|
||||
1,
|
||||
ContractTrieSet{
|
||||
{'a', 0, 1, 0xFF},
|
||||
{'b', 0, 1, 0xFF},
|
||||
{'c', 'e', 0, 1},
|
||||
},
|
||||
}, {
|
||||
[]lookupStrings{
|
||||
{"abc", 1, 3},
|
||||
{"ab", 2, 2},
|
||||
{"a", 3, 1},
|
||||
{"abcd", 1, 3},
|
||||
{"abe", 2, 2},
|
||||
},
|
||||
1,
|
||||
ContractTrieSet{
|
||||
{'a', 0, 1, 3},
|
||||
{'b', 0, 1, 2},
|
||||
{'c', 'c', 0, 1},
|
||||
},
|
||||
}, {
|
||||
[]lookupStrings{
|
||||
{"abc", 1, 3},
|
||||
{"abd", 2, 3},
|
||||
{"ab", 3, 2},
|
||||
{"ac", 4, 2},
|
||||
{"a", 5, 1},
|
||||
{"b", 6, 1},
|
||||
{"ba", 6, 1},
|
||||
},
|
||||
2,
|
||||
ContractTrieSet{
|
||||
{'b', 'b', 0, 6},
|
||||
{'a', 0, 2, 5},
|
||||
{'c', 'c', 0, 4},
|
||||
{'b', 0, 1, 3},
|
||||
{'c', 'd', 0, 1},
|
||||
},
|
||||
}, {
|
||||
[]lookupStrings{
|
||||
{"bcde", 2, 4},
|
||||
{"bc", 7, 2},
|
||||
{"ab", 6, 2},
|
||||
{"bcd", 5, 3},
|
||||
{"abcd", 1, 4},
|
||||
{"abc", 4, 3},
|
||||
{"bcdf", 3, 4},
|
||||
},
|
||||
2,
|
||||
ContractTrieSet{
|
||||
{'b', 3, 1, 0xFF},
|
||||
{'a', 0, 1, 0xFF},
|
||||
{'b', 0, 1, 6},
|
||||
{'c', 0, 1, 4},
|
||||
{'d', 'd', 0, 1},
|
||||
{'c', 0, 1, 7},
|
||||
{'d', 0, 1, 5},
|
||||
{'e', 'f', 0, 2},
|
||||
},
|
||||
}}
|
||||
|
||||
func lookup(c *ContractTrieSet, nnode int, s []uint8) (i, n int) {
|
||||
scan := c.scanner(0, nnode, s)
|
||||
scan.scan(0)
|
||||
return scan.result()
|
||||
}
|
||||
|
||||
func TestLookupContraction(t *testing.T) {
|
||||
for i, tt := range lookupTests {
|
||||
cts := ContractTrieSet(tt.tries)
|
||||
for j, lu := range tt.lookup {
|
||||
str := lu.str
|
||||
for _, s := range []string{str, str + "X"} {
|
||||
const msg = `%d:%d: %s of "%s" %v; want %v`
|
||||
offset, n := lookup(&cts, tt.n, []byte(s))
|
||||
if offset != lu.offset {
|
||||
t.Errorf(msg, i, j, "offset", s, offset, lu.offset)
|
||||
}
|
||||
if n != lu.n {
|
||||
t.Errorf(msg, i, j, "bytes consumed", s, n, len(str))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
vendor/golang.org/x/text/internal/colltab/iter_test.go
generated
vendored
63
vendor/golang.org/x/text/internal/colltab/iter_test.go
generated
vendored
@ -1,63 +0,0 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDoNorm(t *testing.T) {
|
||||
const div = -1 // The insertion point of the next block.
|
||||
tests := []struct {
|
||||
in, out []int
|
||||
}{{
|
||||
in: []int{4, div, 3},
|
||||
out: []int{3, 4},
|
||||
}, {
|
||||
in: []int{4, div, 3, 3, 3},
|
||||
out: []int{3, 3, 3, 4},
|
||||
}, {
|
||||
in: []int{0, 4, div, 3},
|
||||
out: []int{0, 3, 4},
|
||||
}, {
|
||||
in: []int{0, 0, 4, 5, div, 3, 3},
|
||||
out: []int{0, 0, 3, 3, 4, 5},
|
||||
}, {
|
||||
in: []int{0, 0, 1, 4, 5, div, 3, 3},
|
||||
out: []int{0, 0, 1, 3, 3, 4, 5},
|
||||
}, {
|
||||
in: []int{0, 0, 1, 4, 5, div, 4, 4},
|
||||
out: []int{0, 0, 1, 4, 4, 4, 5},
|
||||
},
|
||||
}
|
||||
for j, tt := range tests {
|
||||
i := Iter{}
|
||||
var w, p int
|
||||
for k, cc := range tt.in {
|
||||
|
||||
if cc == div {
|
||||
w = 100
|
||||
p = k
|
||||
continue
|
||||
}
|
||||
i.Elems = append(i.Elems, makeCE([]int{w, defaultSecondary, 2, cc}))
|
||||
}
|
||||
i.doNorm(p, i.Elems[p].CCC())
|
||||
if len(i.Elems) != len(tt.out) {
|
||||
t.Errorf("%d: length was %d; want %d", j, len(i.Elems), len(tt.out))
|
||||
}
|
||||
prevCCC := uint8(0)
|
||||
for k, ce := range i.Elems {
|
||||
if int(ce.CCC()) != tt.out[k] {
|
||||
t.Errorf("%d:%d: unexpected CCC. Was %d; want %d", j, k, ce.CCC(), tt.out[k])
|
||||
}
|
||||
if k > 0 && ce.CCC() == prevCCC && i.Elems[k-1].Primary() > ce.Primary() {
|
||||
t.Errorf("%d:%d: normalization crossed across CCC boundary.", j, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combining rune overflow is tested in search/pattern_test.go.
|
||||
}
|
159
vendor/golang.org/x/text/internal/colltab/numeric_test.go
generated
vendored
159
vendor/golang.org/x/text/internal/colltab/numeric_test.go
generated
vendored
@ -1,159 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/text/internal/testtext"
|
||||
)
|
||||
|
||||
const (
|
||||
digSec = defaultSecondary
|
||||
digTert = defaultTertiary
|
||||
)
|
||||
|
||||
var tPlus3 = e(0, 50, digTert+3)
|
||||
|
||||
// numWeighter is a testWeighter used for testing numericWeighter.
|
||||
var numWeighter = testWeighter{
|
||||
"0": p(100),
|
||||
"0": []Elem{e(100, digSec, digTert+1)}, // U+FF10 FULLWIDTH DIGIT ZERO
|
||||
"₀": []Elem{e(100, digSec, digTert+5)}, // U+2080 SUBSCRIPT ZERO
|
||||
|
||||
"1": p(101),
|
||||
// Allow non-primary collation elements to be inserted.
|
||||
"١": append(p(101), tPlus3), // U+0661 ARABIC-INDIC DIGIT ONE
|
||||
// Allow varying tertiary weight if the number is Nd.
|
||||
"1": []Elem{e(101, digSec, digTert+1)}, // U+FF11 FULLWIDTH DIGIT ONE
|
||||
"2": p(102),
|
||||
// Allow non-primary collation elements to be inserted.
|
||||
"٢": append(p(102), tPlus3), // U+0662 ARABIC-INDIC DIGIT TWO
|
||||
// Varying tertiary weights should be ignored.
|
||||
"2": []Elem{e(102, digSec, digTert+3)}, // U+FF12 FULLWIDTH DIGIT TWO
|
||||
"3": p(103),
|
||||
"4": p(104),
|
||||
"5": p(105),
|
||||
"6": p(106),
|
||||
"7": p(107),
|
||||
// Weights must be strictly monotonically increasing, but do not need to be
|
||||
// consecutive.
|
||||
"8": p(118),
|
||||
"9": p(119),
|
||||
// Allow non-primary collation elements to be inserted.
|
||||
"٩": append(p(119), tPlus3), // U+0669 ARABIC-INDIC DIGIT NINE
|
||||
// Varying tertiary weights should be ignored.
|
||||
"9": []Elem{e(119, digSec, digTert+1)}, // U+FF19 FULLWIDTH DIGIT NINE
|
||||
"₉": []Elem{e(119, digSec, digTert+5)}, // U+2089 SUBSCRIPT NINE
|
||||
|
||||
"a": p(5),
|
||||
"b": p(6),
|
||||
"c": p(8, 2),
|
||||
|
||||
"klm": p(99),
|
||||
|
||||
"nop": p(121),
|
||||
|
||||
"x": p(200),
|
||||
"y": p(201),
|
||||
}
|
||||
|
||||
func p(w ...int) (elems []Elem) {
|
||||
for _, x := range w {
|
||||
e, _ := MakeElem(x, digSec, digTert, 0)
|
||||
elems = append(elems, e)
|
||||
}
|
||||
return elems
|
||||
}
|
||||
|
||||
func TestNumericAppendNext(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
in string
|
||||
w []Elem
|
||||
}{
|
||||
{"a", p(5)},
|
||||
{"klm", p(99)},
|
||||
{"aa", p(5, 5)},
|
||||
{"1", p(120, 1, 101)},
|
||||
{"0", p(120, 0)},
|
||||
{"01", p(120, 1, 101)},
|
||||
{"0001", p(120, 1, 101)},
|
||||
{"10", p(120, 2, 101, 100)},
|
||||
{"99", p(120, 2, 119, 119)},
|
||||
{"9999", p(120, 4, 119, 119, 119, 119)},
|
||||
{"1a", p(120, 1, 101, 5)},
|
||||
{"0b", p(120, 0, 6)},
|
||||
{"01c", p(120, 1, 101, 8, 2)},
|
||||
{"10x", p(120, 2, 101, 100, 200)},
|
||||
{"99y", p(120, 2, 119, 119, 201)},
|
||||
{"9999nop", p(120, 4, 119, 119, 119, 119, 121)},
|
||||
|
||||
// Allow follow-up collation elements if they have a zero non-primary.
|
||||
{"١٢٩", []Elem{e(120), e(3), e(101), tPlus3, e(102), tPlus3, e(119), tPlus3}},
|
||||
{
|
||||
"129",
|
||||
[]Elem{
|
||||
e(120), e(3),
|
||||
e(101, digSec, digTert+1),
|
||||
e(102, digSec, digTert+3),
|
||||
e(119, digSec, digTert+1),
|
||||
},
|
||||
},
|
||||
|
||||
// Ensure AppendNext* adds to the given buffer.
|
||||
{"a10", p(5, 120, 2, 101, 100)},
|
||||
} {
|
||||
nw := NewNumericWeighter(numWeighter)
|
||||
|
||||
b := []byte(tt.in)
|
||||
got := []Elem(nil)
|
||||
for n, sz := 0, 0; n < len(b); {
|
||||
got, sz = nw.AppendNext(got, b[n:])
|
||||
n += sz
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.w) {
|
||||
t.Errorf("AppendNext(%q) =\n%v; want\n%v", tt.in, got, tt.w)
|
||||
}
|
||||
|
||||
got = nil
|
||||
for n, sz := 0, 0; n < len(tt.in); {
|
||||
got, sz = nw.AppendNextString(got, tt.in[n:])
|
||||
n += sz
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.w) {
|
||||
t.Errorf("AppendNextString(%q) =\n%v; want\n%v", tt.in, got, tt.w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNumericOverflow(t *testing.T) {
|
||||
manyDigits := strings.Repeat("9", maxDigits+1) + "a"
|
||||
|
||||
nw := NewNumericWeighter(numWeighter)
|
||||
|
||||
got, n := nw.AppendNextString(nil, manyDigits)
|
||||
|
||||
if n != maxDigits {
|
||||
t.Errorf("n: got %d; want %d", n, maxDigits)
|
||||
}
|
||||
|
||||
if got[1].Primary() != maxDigits {
|
||||
t.Errorf("primary(e[1]): got %d; want %d", n, maxDigits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNumericWeighterAlloc(t *testing.T) {
|
||||
buf := make([]Elem, 100)
|
||||
w := NewNumericWeighter(numWeighter)
|
||||
s := "1234567890a"
|
||||
|
||||
nNormal := testtext.AllocsPerRun(3, func() { numWeighter.AppendNextString(buf, s) })
|
||||
nNumeric := testtext.AllocsPerRun(3, func() { w.AppendNextString(buf, s) })
|
||||
if n := nNumeric - nNormal; n > 0 {
|
||||
t.Errorf("got %f; want 0", n)
|
||||
}
|
||||
}
|
106
vendor/golang.org/x/text/internal/colltab/trie_test.go
generated
vendored
106
vendor/golang.org/x/text/internal/colltab/trie_test.go
generated
vendored
@ -1,106 +0,0 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// We take the smallest, largest and an arbitrary value for each
|
||||
// of the UTF-8 sequence lengths.
|
||||
var testRunes = []rune{
|
||||
0x01, 0x0C, 0x7F, // 1-byte sequences
|
||||
0x80, 0x100, 0x7FF, // 2-byte sequences
|
||||
0x800, 0x999, 0xFFFF, // 3-byte sequences
|
||||
0x10000, 0x10101, 0x10FFFF, // 4-byte sequences
|
||||
0x200, 0x201, 0x202, 0x210, 0x215, // five entries in one sparse block
|
||||
}
|
||||
|
||||
// Test cases for illegal runes.
|
||||
type trietest struct {
|
||||
size int
|
||||
bytes []byte
|
||||
}
|
||||
|
||||
var tests = []trietest{
|
||||
// illegal runes
|
||||
{1, []byte{0x80}},
|
||||
{1, []byte{0xFF}},
|
||||
{1, []byte{t2, tx - 1}},
|
||||
{1, []byte{t2, t2}},
|
||||
{2, []byte{t3, tx, tx - 1}},
|
||||
{2, []byte{t3, tx, t2}},
|
||||
{1, []byte{t3, tx - 1, tx}},
|
||||
{3, []byte{t4, tx, tx, tx - 1}},
|
||||
{3, []byte{t4, tx, tx, t2}},
|
||||
{1, []byte{t4, t2, tx, tx - 1}},
|
||||
{2, []byte{t4, tx, t2, tx - 1}},
|
||||
|
||||
// short runes
|
||||
{0, []byte{t2}},
|
||||
{0, []byte{t3, tx}},
|
||||
{0, []byte{t4, tx, tx}},
|
||||
|
||||
// we only support UTF-8 up to utf8.UTFMax bytes (4 bytes)
|
||||
{1, []byte{t5, tx, tx, tx, tx}},
|
||||
{1, []byte{t6, tx, tx, tx, tx, tx}},
|
||||
}
|
||||
|
||||
func TestLookupTrie(t *testing.T) {
|
||||
for i, r := range testRunes {
|
||||
b := []byte(string(r))
|
||||
v, sz := testTrie.lookup(b)
|
||||
if int(v) != i {
|
||||
t.Errorf("lookup(%U): found value %#x, expected %#x", r, v, i)
|
||||
}
|
||||
if sz != len(b) {
|
||||
t.Errorf("lookup(%U): found size %d, expected %d", r, sz, len(b))
|
||||
}
|
||||
}
|
||||
for i, tt := range tests {
|
||||
v, sz := testTrie.lookup(tt.bytes)
|
||||
if int(v) != 0 {
|
||||
t.Errorf("lookup of illegal rune, case %d: found value %#x, expected 0", i, v)
|
||||
}
|
||||
if sz != tt.size {
|
||||
t.Errorf("lookup of illegal rune, case %d: found size %d, expected %d", i, sz, tt.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test data is taken from exp/collate/locale/build/trie_test.go
|
||||
var testValues = [832]uint32{
|
||||
0x000c: 0x00000001,
|
||||
0x007f: 0x00000002,
|
||||
0x00c0: 0x00000003,
|
||||
0x0100: 0x00000004,
|
||||
0x0140: 0x0000000c, 0x0141: 0x0000000d, 0x0142: 0x0000000e,
|
||||
0x0150: 0x0000000f,
|
||||
0x0155: 0x00000010,
|
||||
0x01bf: 0x00000005,
|
||||
0x01c0: 0x00000006,
|
||||
0x0219: 0x00000007,
|
||||
0x027f: 0x00000008,
|
||||
0x0280: 0x00000009,
|
||||
0x02c1: 0x0000000a,
|
||||
0x033f: 0x0000000b,
|
||||
}
|
||||
|
||||
var testLookup = [640]uint16{
|
||||
0x0e0: 0x05, 0x0e6: 0x06,
|
||||
0x13f: 0x07,
|
||||
0x140: 0x08, 0x144: 0x09,
|
||||
0x190: 0x03,
|
||||
0x1ff: 0x0a,
|
||||
0x20f: 0x05,
|
||||
0x242: 0x01, 0x244: 0x02,
|
||||
0x248: 0x03,
|
||||
0x25f: 0x04,
|
||||
0x260: 0x01,
|
||||
0x26f: 0x02,
|
||||
0x270: 0x04, 0x274: 0x06,
|
||||
}
|
||||
|
||||
var testTrie = Trie{testLookup[6*blockSize:], testValues[:], testLookup[:], testValues[:]}
|
42
vendor/golang.org/x/text/internal/colltab/weighter_test.go
generated
vendored
42
vendor/golang.org/x/text/internal/colltab/weighter_test.go
generated
vendored
@ -1,42 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package colltab
|
||||
|
||||
// testWeighter is a simple Weighter that returns weights from a user-defined map.
|
||||
type testWeighter map[string][]Elem
|
||||
|
||||
func (t testWeighter) Start(int, []byte) int { return 0 }
|
||||
func (t testWeighter) StartString(int, string) int { return 0 }
|
||||
func (t testWeighter) Domain() []string { return nil }
|
||||
func (t testWeighter) Top() uint32 { return 0 }
|
||||
|
||||
// maxContractBytes is the maximum length of any key in the map.
|
||||
const maxContractBytes = 10
|
||||
|
||||
func (t testWeighter) AppendNext(buf []Elem, s []byte) ([]Elem, int) {
|
||||
n := len(s)
|
||||
if n > maxContractBytes {
|
||||
n = maxContractBytes
|
||||
}
|
||||
for i := n; i > 0; i-- {
|
||||
if e, ok := t[string(s[:i])]; ok {
|
||||
return append(buf, e...), i
|
||||
}
|
||||
}
|
||||
panic("incomplete testWeighter: could not find " + string(s))
|
||||
}
|
||||
|
||||
func (t testWeighter) AppendNextString(buf []Elem, s string) ([]Elem, int) {
|
||||
n := len(s)
|
||||
if n > maxContractBytes {
|
||||
n = maxContractBytes
|
||||
}
|
||||
for i := n; i > 0; i-- {
|
||||
if e, ok := t[s[:i]]; ok {
|
||||
return append(buf, e...), i
|
||||
}
|
||||
}
|
||||
panic("incomplete testWeighter: could not find " + s)
|
||||
}
|
Reference in New Issue
Block a user