package util

import (
	"testing"

	"github.com/tidbcloud/devops/pkg/infra/utils/test"
)

func TestFormatItems(t *testing.T) {
	cases := map[string]struct {
		lines  []string
		indent string
		prefix string
		expect string
	}{
		"normal": {
			lines:  []string{"a", "b", "c"},
			indent: "  ",
			prefix: "- ",
			expect: `  - a
  - b
  - c`,
		},
		"one line": {
			lines:  []string{"a"},
			indent: "  ",
			prefix: "- ",
			expect: `  - a`,
		},
	}

	for name, c := range cases {
		t.Run(name, func(t *testing.T) {
			got := FormatItems(c.lines, c.indent, c.prefix)
			if err := test.IsEqual(c.expect, got); err != nil {
				t.Fatal(err)
			}
		})
	}
}
