github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/pipes/term/utils_test.go (about)

     1  package term
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test/count"
     7  )
     8  
     9  func TestAppendBytes(t *testing.T) {
    10  	tests := []struct {
    11  		Slice    string
    12  		Data     string
    13  		Expected string
    14  	}{
    15  		{
    16  			Slice:    "",
    17  			Data:     "",
    18  			Expected: "",
    19  		},
    20  		{
    21  			Slice:    "",
    22  			Data:     "bar",
    23  			Expected: "bar",
    24  		},
    25  		{
    26  			Slice:    "foo",
    27  			Data:     "",
    28  			Expected: "foo",
    29  		},
    30  		{
    31  			Slice:    "foo",
    32  			Data:     "bar",
    33  			Expected: "foobar",
    34  		},
    35  		{
    36  			Slice:    "foo",
    37  			Data:     "barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar",
    38  			Expected: "foobarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar",
    39  		},
    40  	}
    41  
    42  	count.Tests(t, len(tests))
    43  
    44  	for i, test := range tests {
    45  		b := appendBytes([]byte(test.Slice), []byte(test.Data)...)
    46  		actual := string(b)
    47  		if actual != test.Expected {
    48  			t.Errorf("Actual does not match expected in test %d", i)
    49  			t.Logf("  Slice:    '%s'", test.Slice)
    50  			t.Logf("  Data:     '%s'", test.Data)
    51  			t.Logf("  Expected: '%s'", test.Expected)
    52  			t.Logf("  Actual:   '%s'", actual)
    53  		}
    54  	}
    55  }