Exemplo n.º 1
0
func doTest(t Test) {
	bld := build.NewBuilder()
	parseUCA(bld)
	c, err := bld.Build()
	Error(err)
	c.Strength = collate.Tertiary
	c.Alternate = collate.AltShifted
	b := &collate.Buffer{}
	if strings.Contains(t.name, "NON_IGNOR") {
		c.Alternate = collate.AltNonIgnorable
	}

	prev := t.str[0]
	for i := 1; i < len(t.str); i++ {
		s := t.str[i]
		ka := c.Key(b, prev)
		kb := c.Key(b, s)
		if r := bytes.Compare(ka, kb); r == 1 {
			fail(t, "%d: Key(%.4X) < Key(%.4X) (%X < %X) == %d; want -1 or 0", i, []rune(string(prev)), []rune(string(s)), ka, kb, r)
			prev = s
			continue
		}
		if r := c.Compare(b, prev, s); r == 1 {
			fail(t, "%d: Compare(%.4X, %.4X) == %d; want -1 or 0", i, runes(prev), runes(s), r)
		}
		if r := c.Compare(b, s, prev); r == -1 {
			fail(t, "%d: Compare(%.4X, %.4X) == %d; want 1 or 0", i, runes(s), runes(prev), r)
		}
		prev = s
	}
}
Exemplo n.º 2
0
func makeTable(in []input) (*collate.Collator, error) {
	b := build.NewBuilder()
	for _, r := range in {
		b.Add([]rune(r.str), r.ces)
	}
	return b.Build("")
}
Exemplo n.º 3
0
func main() {
	flag.Parse()
	b := build.NewBuilder()
	if *root != "" {
		parseUCA(b)
	}
	if *cldr != "" {
		if tables.contains("chars") {
			parseMain()
		}
		parseCollation(b)
	}

	c, err := b.Build()
	failOnError(err)

	if *test {
		testCollator(c)
	} else {
		fmt.Println("// Generated by running")
		fmt.Printf("//  maketables -root=%s -cldr=%s\n", *root, *cldr)
		fmt.Println("// DO NOT EDIT")
		fmt.Println("// TODO: implement more compact representation for sparse blocks.")
		if *tags != "" {
			fmt.Printf("// +build %s\n", *tags)
		}
		fmt.Println("")
		fmt.Printf("package %s\n", *pkg)
		if tables.contains("collate") {
			fmt.Println("")
			_, err = b.Print(os.Stdout)
			failOnError(err)
		}
		if tables.contains("chars") {
			printExemplarCharacters(os.Stdout)
		}
	}
}