github.com/enetx/g@v1.0.80/tests/string_compdecomp_test.go (about)

     1  package g_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/enetx/g"
     7  )
     8  
     9  func TestStringCompressionAndDecompression(t *testing.T) {
    10  	// Test data
    11  	inputData := g.NewString("hello world")
    12  
    13  	// Test Zstd compression and decompression
    14  	zstdCompressed := inputData.Comp().Zstd()
    15  	zstdDecompressed := zstdCompressed.Decomp().Zstd()
    16  	if zstdDecompressed.IsErr() || zstdDecompressed.Unwrap().Ne(inputData) {
    17  		t.Errorf(
    18  			"Zstd compression and decompression failed. Input: %s, Decompressed: %s",
    19  			inputData,
    20  			zstdDecompressed.Unwrap(),
    21  		)
    22  	}
    23  
    24  	// Test Brotli compression and decompression
    25  	brotliCompressed := inputData.Comp().Brotli()
    26  	brotliDecompressed := brotliCompressed.Decomp().Brotli()
    27  	if brotliDecompressed.IsErr() || brotliDecompressed.Unwrap().Ne(inputData) {
    28  		t.Errorf(
    29  			"Brotli compression and decompression failed. Input: %s, Decompressed: %s",
    30  			inputData,
    31  			brotliDecompressed.Unwrap(),
    32  		)
    33  	}
    34  
    35  	// Test Zlib compression and decompression
    36  	zlibCompressed := inputData.Comp().Zlib()
    37  	zlibDecompressed := zlibCompressed.Decomp().Zlib()
    38  	if zlibDecompressed.IsErr() || zlibDecompressed.Unwrap().Ne(inputData) {
    39  		t.Errorf(
    40  			"Zlib compression and decompression failed. Input: %s, Decompressed: %s",
    41  			inputData,
    42  			zlibDecompressed.Unwrap(),
    43  		)
    44  	}
    45  
    46  	// Test Gzip compression and decompression
    47  	gzipCompressed := inputData.Comp().Gzip()
    48  	gzipDecompressed := gzipCompressed.Decomp().Gzip()
    49  	if gzipDecompressed.IsErr() || gzipDecompressed.Unwrap().Ne(inputData) {
    50  		t.Errorf(
    51  			"Gzip compression and decompression failed. Input: %s, Decompressed: %s",
    52  			inputData,
    53  			gzipDecompressed.Unwrap(),
    54  		)
    55  	}
    56  
    57  	// Test Flate compression and decompression
    58  	flateCompressed := inputData.Comp().Flate()
    59  	flateDecompressed := flateCompressed.Decomp().Flate()
    60  	if flateDecompressed.IsErr() || flateDecompressed.Unwrap().Ne(inputData) {
    61  		t.Errorf(
    62  			"Flate compression and decompression failed. Input: %s, Decompressed: %s",
    63  			inputData,
    64  			flateDecompressed.Unwrap(),
    65  		)
    66  	}
    67  }