示例#1
0
文件: sort_test.go 项目: jmesmon/gcc
func ExampleCollator_Strings() {
	c := collate.New("root")
	strings := []string{
		"ad",
		"äb",
		"ac",
	}
	c.Strings(strings)
	fmt.Println(strings)
	// Output: [äb ac ad]
}
示例#2
0
文件: sort_test.go 项目: jmesmon/gcc
func TestSort(t *testing.T) {
	c := collate.New("en")
	strings := []string{
		"bcd",
		"abc",
		"ddd",
	}
	c.Sort(sorter(strings))
	res := fmt.Sprint(strings)
	want := "[abc bcd ddd]"
	if res != want {
		t.Errorf("found %s; want %s", res, want)
	}
}
示例#3
0
func testCollator(c *collate.Collator) {
	c0 := collate.New("")

	// iterator over all characters for all locales and check
	// whether Key is equal.
	buf := collate.Buffer{}

	// Add all common and not too uncommon runes to the test set.
	for i := rune(0); i < 0x30000; i++ {
		testInput.add(string(i))
	}
	for i := rune(0xE0000); i < 0xF0000; i++ {
		testInput.add(string(i))
	}
	for _, str := range testInput.values() {
		k0 := c0.KeyFromString(&buf, str)
		k := c.KeyFromString(&buf, str)
		if !bytes.Equal(k0, k) {
			failOnError(fmt.Errorf("test:%U: keys differ (%x vs %x)", []rune(str), k0, k))
		}
		buf.Reset()
	}
	fmt.Println("PASS")
}
示例#4
0
文件: col.go 项目: hfeeki/go
func newGoCollator(locale string) (Collator, error) {
	c := &goCollator{c: collate.New(locale)}
	return c, nil
}