diff options
Diffstat (limited to 'src/pkg/compress/gzip/gzip_test.go')
-rw-r--r-- | src/pkg/compress/gzip/gzip_test.go | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/pkg/compress/gzip/gzip_test.go b/src/pkg/compress/gzip/gzip_test.go index 121e627e6..eb7a7ec08 100644 --- a/src/pkg/compress/gzip/gzip_test.go +++ b/src/pkg/compress/gzip/gzip_test.go @@ -5,9 +5,12 @@ package gzip import ( + "bufio" + "bytes" "io" "io/ioutil" "testing" + "time" ) // pipe creates two ends of a pipe that gzip and gunzip, and runs dfunc at the @@ -51,9 +54,10 @@ func TestEmpty(t *testing.T) { func TestWriter(t *testing.T) { pipe(t, func(compressor *Compressor) { - compressor.Comment = "comment" + compressor.Comment = "Äußerung" + //compressor.Comment = "comment" compressor.Extra = []byte("extra") - compressor.Mtime = 1e8 + compressor.ModTime = time.Unix(1e8, 0) compressor.Name = "name" _, err := compressor.Write([]byte("payload")) if err != nil { @@ -68,17 +72,43 @@ func TestWriter(t *testing.T) { if string(b) != "payload" { t.Fatalf("payload is %q, want %q", string(b), "payload") } - if decompressor.Comment != "comment" { - t.Fatalf("comment is %q, want %q", decompressor.Comment, "comment") + if decompressor.Comment != "Äußerung" { + t.Fatalf("comment is %q, want %q", decompressor.Comment, "Äußerung") } if string(decompressor.Extra) != "extra" { t.Fatalf("extra is %q, want %q", decompressor.Extra, "extra") } - if decompressor.Mtime != 1e8 { - t.Fatalf("mtime is %d, want %d", decompressor.Mtime, uint32(1e8)) + if decompressor.ModTime.Unix() != 1e8 { + t.Fatalf("mtime is %d, want %d", decompressor.ModTime.Unix(), uint32(1e8)) } if decompressor.Name != "name" { t.Fatalf("name is %q, want %q", decompressor.Name, "name") } }) } + +func TestLatin1(t *testing.T) { + latin1 := []byte{0xc4, 'u', 0xdf, 'e', 'r', 'u', 'n', 'g', 0} + utf8 := "Äußerung" + z := Decompressor{r: bufio.NewReader(bytes.NewBuffer(latin1))} + s, err := z.readString() + if err != nil { + t.Fatalf("%v", err) + } + if s != utf8 { + t.Fatalf("string is %q, want %q", s, utf8) + } + + buf := bytes.NewBuffer(make([]byte, 0, len(latin1))) + c := Compressor{w: buf} + if err = c.writeString(utf8); err != nil { + t.Fatalf("%v", err) + } + s = buf.String() + if s != string(latin1) { + t.Fatalf("string is %v, want %v", s, latin1) + } + //if s, err = buf.ReadString(0); err != nil { + //t.Fatalf("%v", err) + //} +} |