package cfl import ( "bytes" "encoding/binary" "encoding/hex" "errors" "reflect" "testing" ) func write(t testing.TB, entries []Entry) []byte { t.Helper() var b bytes.Buffer if err := Write(&b, entries); err != nil { t.Fatal(err) } return b.Bytes() } func TestWriteLayout(t *testing.T) { got := write(t, []Entry{{Name: "a", Data: []byte("xy")}, {Name: "é", Data: nil}}) want := "" + "43464c33" + "16000000" + "1e000000" + // CFL3, directory at 22, 30 bytes "02000000" + "7879" + // "a" "00000000" + // "é" "00000000" + "1e000000" + // directory: uncompressed, 30 bytes "02000000" + "0c000000" + "00000000" + "0100" + "61" + "00000000" + "12000000" + "00000000" + "0100" + "e9" if hex.EncodeToString(got) != want { t.Errorf("got %x\nwant %s", got, want) } } func TestRoundTrip(t *testing.T) { entries := []Entry{ {Name: "index.xml", Data: []byte("