func doTest(t Test) { bld := build.NewBuilder() parseUCA(bld) w, err := bld.Build() Error(err) c := collate.NewFromTable(w) c.Strength = colltab.Quaternary c.Alternate = collate.AltShifted b := &collate.Buffer{} if strings.Contains(t.name, "NON_IGNOR") { c.Strength = colltab.Tertiary c.Alternate = collate.AltNonIgnorable } prev := t.str[0] for i := 1; i < len(t.str); i++ { b.Reset() 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(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(s, prev); r == -1 { fail(t, "%d: Compare(%.4X, %.4X) == %d; want 1 or 0", i, runes(s), runes(prev), r) } prev = s } }
func main() { flag.Parse() b := build.NewBuilder() if *root != "" { parseUCA(b) } if *cldrzip != "" { if tables.contains("chars") { parseMain() } parseCollation(b) } c, err := b.Build() failOnError(err) if *test { testCollator(collate.NewFromTable(c)) } else { fmt.Println("// Generated by running") fmt.Printf("// maketables -root=%s -cldr=%s\n", *root, *cldrzip) 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) } } }