Exemple #1
0
func ExampleCollator_Strings() {
	c := collate.New(language.Und)
	strings := []string{
		"ad",
		"ab",
		"äb",
		"ac",
	}
	c.SortStrings(strings)
	fmt.Println(strings)
	// Output: [ab äb ac ad]
}
Exemple #2
0
func TestSort(t *testing.T) {
	c := collate.New(language.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)
	}
}
Exemple #3
0
func testCollator(c *collate.Collator) {
	c0 := collate.New(locale.Und)

	// 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")
}
Exemple #4
0
func newGoCollator(loc string) (Collator, error) {
	c := &goCollator{c: collate.New(language.Make(loc))}
	return c, nil
}