─── Layer 11: StringArrayFlag.Set (BUG-26) ────────────────────────────────── TestStringArrayFlagSetEmptyValues verifies that StringArrayFlag.Set never appends empty strings. BUG-26: strings.Split(value, ",") yields a single empty entry for "" and adjacent empty entries for "a,", ",a", and "a,,b". A
(t *testing.T)
| 919 | // excludeDirs makes filepath.Rel(".", dir) succeed for every file, silently |
| 920 | // excluding the entire tree from analysis. |
| 921 | func TestStringArrayFlagSetEmptyValues(t *testing.T) { |
| 922 | tests := []struct { |
| 923 | name string |
| 924 | input string |
| 925 | want []string |
| 926 | }{ |
| 927 | {"empty string yields no entries", "", nil}, |
| 928 | {"single non-empty value", "a", []string{"a"}}, |
| 929 | {"trailing comma drops empty tail", "a,", []string{"a"}}, |
| 930 | {"leading comma drops empty head", ",a", []string{"a"}}, |
| 931 | {"adjacent commas drop empty middle", "a,,b", []string{"a", "b"}}, |
| 932 | {"only commas yields no entries", ",,", nil}, |
| 933 | {"surrounding whitespace trimmed", " a , b ", []string{"a", "b"}}, |
| 934 | {"tab whitespace trimmed", "\ta\t,\tb\t", []string{"a", "b"}}, |
| 935 | {"whitespace-only entries dropped", " , a , ", []string{"a"}}, |
| 936 | {"internal whitespace preserved", "my path,other path", []string{"my path", "other path"}}, |
| 937 | } |
| 938 | for _, tc := range tests { |
| 939 | t.Run(tc.name, func(t *testing.T) { |
| 940 | var f StringArrayFlag |
| 941 | if err := f.Set(tc.input); err != nil { |
| 942 | t.Fatalf("Set(%q) returned error: %v", tc.input, err) |
| 943 | } |
| 944 | if len(f) != len(tc.want) { |
| 945 | t.Fatalf("Set(%q): got %d entries %v, want %d entries %v", |
| 946 | tc.input, len(f), []string(f), len(tc.want), tc.want) |
| 947 | } |
| 948 | for i := range f { |
| 949 | if f[i] != tc.want[i] { |
| 950 | t.Errorf("Set(%q)[%d] = %q, want %q", tc.input, i, f[i], tc.want[i]) |
| 951 | } |
| 952 | } |
| 953 | }) |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | // ─── Layer 12: commentGroupHasOptIn / isExcluded / commentHasDirective ─────── |
| 958 |
nothing calls this directly
no test coverage detected
searching dependent graphs…