MCPcopy Create free account
hub / github.com/dkorunic/betteralign / TestStringArrayFlagSetEmptyValues

Function TestStringArrayFlagSetEmptyValues

betteralign_unit_test.go:921–955  ·  view source on GitHub ↗

─── 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)

Source from the content-addressed store, hash-verified

919// excludeDirs makes filepath.Rel(".", dir) succeed for every file, silently
920// excluding the entire tree from analysis.
921func 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

Callers

nothing calls this directly

Calls 1

SetMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…