package predictor import ( diff "0dev.org/diff" "bytes" "io/ioutil" "testing" ) func TestRFC(t *testing.T) { input := []byte{0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x0a, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x0a, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x0a} output := []byte{0x60, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x60, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0a, 0x6f, 0x41, 0x0a, 0x6f, 0x41, 0x0a, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x0a, 0x60, 0x42, 0x41, 0x42, 0x41, 0x42, 0x0a, 0x60, 0x78, 0x78, 0x78, 0x78, 0x78, 0x0a} var buf bytes.Buffer var err error out := Compressor(&buf) err = out(input) if err != nil { t.Error(err) } err = out([]byte{}) if err != nil { t.Error(err) } result := buf.Bytes() delta := diff.Diff(diff.D{len(result), len(output), func(i, j int) bool { return result[i] == output[j] }}) if len(delta.Added) > 0 || len(delta.Removed) > 0 { t.Error("Unexpected compressed output", delta) } data := bytes.NewBuffer(result) in := Decompressor(data) result, err = ioutil.ReadAll(in) delta = diff.Diff(diff.D{len(result), len(input), func(i, j int) bool { return result[i] == input[j] }}) if len(delta.Added) > 0 || len(delta.Removed) > 0 { t.Error("Unexpected compressed output", delta) } }