Skip to content

Git designed for AI agents.

910 B
Raw Blame
package text_test

import (
	"testing"

	"github.com/feder-cr/git-ai/internal/helper/text"
	"github.com/stretchr/testify/require"
)

func TestChompBytes(t *testing.T) {
	testCases := []struct {
		desc string
		in   []byte
		out  string
	}{
		{desc: "no space, trailing newline", in: []byte("hello world\n"), out: "hello world"},
		{desc: "space, trailing newline", in: []byte(" hello world \n"), out: " hello world "},
		{desc: "no space, no trailing newline", in: []byte("hello world"), out: "hello world"},
		{desc: "space, no trailing newline", in: []byte(" hello world "), out: " hello world "},
		{desc: "double newline", in: []byte(" hello world \n\n"), out: " hello world \n"},
		{desc: "empty slice", in: []byte{}, out: ""},
		{desc: "nil slice", in: nil, out: ""},
	}

	for _, tc := range testCases {
		t.Run(tc.desc, func(t *testing.T) {
			require.Equal(t, tc.out, text.ChompBytes(tc.in))
		})
	}
}