1package fileio23import "testing"45// TestFormats checks every row of the formats table is complete, since6// the UI's lists and Import and Export all come from it.7func TestFormats(t *testing.T) {8 for i, k := range Kinds() {9 f := k.format()10 if f.kind != k || k != Kind(i+1) {11 t.Errorf("row %d is %v, want Kind order", i, f.kind)12 }13 if f.name == "" || f.noun == "" || f.label == "" || len(f.exts) == 0 || f.read == nil && f.write == nil {14 t.Errorf("%v: incomplete %+v", k, f)15 }16 checkExts(t, k)17 if k.CanExport() != (k.MenuTitle() != "") || k.CanExport() != (k.About() != "") {18 t.Errorf("%v: export %v, menu %q, about %q", k, k.CanExport(), k.MenuTitle(), k.About())19 }20 }21 if XLSX.MenuTitle() != "Microsoft Excel (.xlsx)" || !XLSX.HoldsSheets() || CSV.HoldsSheets() {22 t.Errorf("XLSX: %q, holds sheets %v", XLSX.MenuTitle(), XLSX.HoldsSheets())23 }24 if !SQLite.HasTables() || XLSX.HasTables() {25 t.Errorf("only SQLite has tables")26 }27 if k := Kind(99); k.String() != "unknown" || k.Ext() != "" || k.CanExport() {28 t.Errorf("unknown kind %q %q %v", k, k.Ext(), k.CanExport())29 }30 if _, ok := KindOf("notes.txt"); ok {31 t.Errorf("KindOf(.txt) recognized")32 }33}3435// checkExts checks each of k's extensions finds k, for import only36// when 012 imports it.37func checkExts(t *testing.T, k Kind) {38 t.Helper()39 for _, e := range k.format().exts {40 if got, ok := ExportKindOf("x" + e); !ok || got != k {41 t.Errorf("ExportKindOf(x%s) = %v, %v", e, got, ok)42 }43 if got, ok := KindOf("x" + e); ok != k.CanImport() || ok && got != k {44 t.Errorf("KindOf(x%s) = %v, %v", e, got, ok)45 }46 }47}