aboutsummaryrefslogtreecommitdiff
path: root/internal/compress
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-05 21:30:38 +0800
committerGravatar Runxi Yu2026-03-05 21:30:38 +0800
commit9ab5800ec4f9d9aac97cb4bb2ae9f0f8dd488678 (patch)
treecf54c700e28c77a12b98baf34629662b866c862b /internal/compress
parent*: Fix various lints (diff)
signatureNo signature
internal/compress/zlib: Fix testpkg
Diffstat (limited to 'internal/compress')
-rw-r--r--internal/compress/zlib/reader_test.go14
-rw-r--r--internal/compress/zlib/writer_test.go34
2 files changed, 26 insertions, 22 deletions
diff --git a/internal/compress/zlib/reader_test.go b/internal/compress/zlib/reader_test.go
index 13f32dbc..c64bd5b0 100644
--- a/internal/compress/zlib/reader_test.go
+++ b/internal/compress/zlib/reader_test.go
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package zlib
+package zlib_test
import (
"bytes"
"errors"
"io"
"testing"
+
+ "codeberg.org/lindenii/furgit/internal/compress/zlib"
)
type zlibTest struct {
@@ -71,21 +73,21 @@ var zlibTests = []zlibTest{
"",
[]byte{0x88, 0x98, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
nil,
- ErrHeader,
+ zlib.ErrHeader,
},
{
"bad header (FCHECK)",
"",
[]byte{0x78, 0x9f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01},
nil,
- ErrHeader,
+ zlib.ErrHeader,
},
{
"bad checksum",
"",
[]byte{0x78, 0x9c, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff},
nil,
- ErrChecksum,
+ zlib.ErrChecksum,
},
{
"not enough data",
@@ -128,7 +130,7 @@ var zlibTests = []zlibTest{
[]byte{
0x48, 0x65, 0x6c, 0x6c,
},
- ErrDictionary,
+ zlib.ErrDictionary,
},
{
"truncated zlib stream amid raw-block",
@@ -157,7 +159,7 @@ func TestDecompressor(t *testing.T) {
for _, tt := range zlibTests {
in := bytes.NewReader(tt.compressed)
- zr, err := NewReaderDict(in, tt.dict)
+ zr, err := zlib.NewReaderDict(in, tt.dict)
if err != nil {
if !errors.Is(err, tt.err) {
t.Errorf("%s: NewReader: %s", tt.desc, err)
diff --git a/internal/compress/zlib/writer_test.go b/internal/compress/zlib/writer_test.go
index 2a8318a6..f3bfb437 100644
--- a/internal/compress/zlib/writer_test.go
+++ b/internal/compress/zlib/writer_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package zlib
+package zlib_test
import (
"bytes"
@@ -10,6 +10,8 @@ import (
"io"
"os"
"testing"
+
+ "codeberg.org/lindenii/furgit/internal/compress/zlib"
)
var filenames = []string{
@@ -79,7 +81,7 @@ func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
}
}()
- zlibw, err := NewWriterLevelDict(pipew, level, dict)
+ zlibw, err := zlib.NewWriterLevelDict(pipew, level, dict)
if err != nil {
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
@@ -101,7 +103,7 @@ func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
}
}()
- zlibr, err := NewReaderDict(piper, dict)
+ zlibr, err := zlib.NewReaderDict(piper, dict)
if err != nil {
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
@@ -144,11 +146,11 @@ func TestWriter(t *testing.T) {
for i, s := range data {
b := []byte(s)
tag := fmt.Sprintf("#%d", i)
- testLevelDict(t, tag, b, DefaultCompression, "")
- testLevelDict(t, tag, b, NoCompression, "")
- testLevelDict(t, tag, b, HuffmanOnly, "")
+ testLevelDict(t, tag, b, zlib.DefaultCompression, "")
+ testLevelDict(t, tag, b, zlib.NoCompression, "")
+ testLevelDict(t, tag, b, zlib.HuffmanOnly, "")
- for level := BestSpeed; level <= BestCompression; level++ {
+ for level := zlib.BestSpeed; level <= zlib.BestCompression; level++ {
testLevelDict(t, tag, b, level, "")
}
}
@@ -158,11 +160,11 @@ func TestWriterBig(t *testing.T) {
t.Parallel()
for i, fn := range filenames {
- testFileLevelDict(t, fn, DefaultCompression, "")
- testFileLevelDict(t, fn, NoCompression, "")
- testFileLevelDict(t, fn, HuffmanOnly, "")
+ testFileLevelDict(t, fn, zlib.DefaultCompression, "")
+ testFileLevelDict(t, fn, zlib.NoCompression, "")
+ testFileLevelDict(t, fn, zlib.HuffmanOnly, "")
- for level := BestSpeed; level <= BestCompression; level++ {
+ for level := zlib.BestSpeed; level <= zlib.BestCompression; level++ {
testFileLevelDict(t, fn, level, "")
if level >= 1 && testing.Short() {
@@ -181,11 +183,11 @@ func TestWriterDict(t *testing.T) {
const dictionary = "0123456789."
for i, fn := range filenames {
- testFileLevelDict(t, fn, DefaultCompression, dictionary)
- testFileLevelDict(t, fn, NoCompression, dictionary)
- testFileLevelDict(t, fn, HuffmanOnly, dictionary)
+ testFileLevelDict(t, fn, zlib.DefaultCompression, dictionary)
+ testFileLevelDict(t, fn, zlib.NoCompression, dictionary)
+ testFileLevelDict(t, fn, zlib.HuffmanOnly, dictionary)
- for level := BestSpeed; level <= BestCompression; level++ {
+ for level := zlib.BestSpeed; level <= zlib.BestCompression; level++ {
testFileLevelDict(t, fn, level, dictionary)
if level >= 1 && testing.Short() {
@@ -207,7 +209,7 @@ func TestWriterDictIsUsed(t *testing.T) {
buf bytes.Buffer
)
- compressor, err := NewWriterLevelDict(&buf, BestCompression, input)
+ compressor, err := zlib.NewWriterLevelDict(&buf, zlib.BestCompression, input)
if err != nil {
t.Errorf("error in NewWriterLevelDict: %s", err)