// Copyright 2026 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package utils import ( "reflect" "testing" "github.com/stretchr/testify/assert" ) func TestSplitCSV(t *testing.T) { cases := []struct { name string in string want []string }{ {name: "empty", in: "", want: nil}, {name: "single", in: "alice", want: []string{"alice"}}, {name: "two", in: "alice,bob", want: []string{"alice", "bob"}}, {name: "trailing comma", in: "alice,bob,", want: []string{"alice", "bob"}}, {name: "leading comma", in: ",alice,bob", want: []string{"alice", "bob"}}, {name: "double comma", in: "alice,,bob", want: []string{"alice", "bob"}}, {name: "only commas", in: ",,,", want: nil}, {name: "whitespace around entries trimmed", in: " alice , bob ", want: []string{"alice", "bob"}}, {name: "whitespace-only entries dropped", in: "alice, ,bob", want: []string{"alice", "bob"}}, {name: "tabs and newlines trimmed", in: "\talice\n,\t\nbob", want: []string{"alice", "bob"}}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := SplitCSV(tc.in) if !reflect.DeepEqual(got, tc.want) { t.Errorf("SplitCSV(%q) = %#v, want %#v", tc.in, got, tc.want) } }) } } func TestSplitCSVEmptyReturnsNilNotEmptySlice(t *testing.T) { // Regression: previously GetValues returned []string{""} for empty // input, which confused length-based "is this flag set?" checks at // every call site. nil round-trips cleanly through encoding/json. got := SplitCSV("") assert.Nil(t, got) got = SplitCSV(",,,") assert.Nil(t, got) }