// Copyright 2015, Joe Tsai. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE.md file. package meta import ( "bytes" "io" "math/rand" "testing" "github.com/dsnet/compress/internal/errors" "github.com/dsnet/compress/internal/testutil" ) // TestWriter tests that the encoded output matches the expected output exactly. // A failure here does not necessarily mean that the encoder is wrong since // there are many possible representations. Before changing the test vectors to // make a test pass, one must verify the new output is correct. func TestWriter(t *testing.T) { db := testutil.MustDecodeBitGen dh := testutil.MustDecodeHex errFuncs := map[string]func(error) bool{ "IsInvalid": errors.IsInvalid, } vectors := []struct { desc string // Description of the text input []byte // Test input string output []byte // Expected output string final FinalMode // Input final mode errf string // Name of error checking callback }{{ desc: "empty meta block (FinalNil)", input: dh(""), output: db(`<<< < (0 10) (00011 00000 1010) (011 000 011 001 000 (000 000)*4 010) 0 > (111 10 (111 10 0 10 0 (110 10 0*2 10 0*3 10 0 (110 10 0 10*2 0*3 10 0 (110 0*2 10 0 10*2 0 (110 10 0 10 0 10*2 0 (110 10 0 10 0 10*2 0 (110 10 0*3 10 (111 10 0 (110 10 0 (110 10*2 0*2 10 (111 10*2 0*3 10 (111 10*2 0 (110 10 0 (110 10*2 0*3 10 0 10 0 (110 10 0*2 10*2 0 10*2 (0 10)*87 (111 10 0 10*3 0 10*2 (0 10)*91 (111 0 (110 0 10 0 10 0*2 10*3 (0 10)*99 (111 0 10 0*2 10 0 10*3 (0 10)*103 (111 0*3 10*2 0 10*3 (0 10)*107 (111 0 10 0*3 10 (110 0 10 0 10 0 10 (110 0 (110 0*2 10 (110 0 10*2 0 10 (110