processor/similar_flags_test.go GO 177 lines View on github.com → Search inside
1package processor23import (4	"slices"5	"testing"67	"github.com/spf13/pflag"8)910func TestStringSimilarRatio(t *testing.T) {11	testCases := []struct {12		s1, s2    string13		isSimilar bool14	}{15		{16			s1:        "",17			s2:        "",18			isSimilar: false,19		},20		{21			s1:        "",22			s2:        "hello",23			isSimilar: false,24		},25		{26			s1:        "hello",27			s2:        "",28			isSimilar: false,29		},30		{31			s1:        "hello",32			s2:        "hello",33			isSimilar: true,34		},35		{36			s1:        "hello",37			s2:        "Hello",38			isSimilar: true,39		},40		{41			s1:        "hello",42			s2:        "helle",43			isSimilar: true,44		},45		{46			s1:        "hello",47			s2:        "hallo",48			isSimilar: true,49		},50		{51			s1:        "hello",52			s2:        "helo",53			isSimilar: true,54		},55		{56			s1:        "hello",57			s2:        "hell",58			isSimilar: true,59		},60		{61			s1:        "hello",62			s2:        "heelo",63			isSimilar: true,64		},65		{66			s1:        "uloc",67			s2:        "ulc",68			isSimilar: true,69		},70		{71			s1:        "uloc",72			s2:        "ulcc",73			isSimilar: true,74		},75		{76			s1:        "uloc",77			s2:        "ulocc",78			isSimilar: true,79		},80		{81			s1:        "--ci",82			s2:        "--cii",83			isSimilar: true,84		},85		{86			s1:        "hello",87			s2:        "hello-world",88			isSimilar: false,89		},90		{91			s1:        "hello",92			s2:        "how",93			isSimilar: false,94		},95		{96			s1:        "hello",97			s2:        "HELLO",98			isSimilar: false,99		},100		{101			s1:        "python",102			s2:        "golang",103			isSimilar: false,104		},105	}106	for _, tc := range testCases {107		result := StringSimilarRatio(tc.s1, tc.s2) >= SimilarStringThreshold108		if result != tc.isSimilar {109			t.Errorf("StringSimilarRatio(%q, %q) failed, got %v, want %v", tc.s1, tc.s2, result, tc.isSimilar)110		}111	}112}113114func TestGetMostSimilarFlags(t *testing.T) {115	flags := pflag.NewFlagSet("testing", pflag.ExitOnError)116	_ = flags.Bool("no-ignore", false, "test")117	_ = flags.Bool("no-gitignore", false, "test")118	_ = flags.Int("no-gitmodule", 0, "test")119	_ = flags.String("format", "", "test")120	_ = flags.String("uloc", "", "test")121	_ = flags.String("gen", "", "test")122	_ = flags.String("ci", "", "test")123124	testCases := []struct {125		name    string126		expects []string127	}{128		{129			name:    "",130			expects: []string{},131		},132		{133			name:    "unknown",134			expects: []string{},135		},136		{137			name:    "no-gignore",138			expects: []string{"no-ignore", "no-gitignore"},139		},140		{141			name:    "no-gitmodyle",142			expects: []string{"no-gitmodule"},143		},144		{145			name:    "formet",146			expects: []string{"format"},147		},148		{149			name:    "ulc",150			expects: []string{"uloc"},151		},152		{153			name:    "gan",154			expects: []string{"gen"},155		},156		{157			name:    "cii",158			expects: []string{"ci"},159		},160		// these two are not included in the set, but still need to be matched161		{162			name:    "vrsion",163			expects: []string{"version"},164		},165		{166			name:    "hellp",167			expects: []string{"help"},168		},169	}170	for _, tc := range testCases {171		result := GetMostSimilarFlags(flags, tc.name)172		if !slices.Equal(result, tc.expects) {173			t.Errorf("got: %v, want: %v", result, tc.expects)174		}175	}176}

Code quality findings 3

Blank identifier discarding results; verify intentional ignoring of return values
warning correctness blank-identifier-discard
_ = flags.String("uloc", "", "test")
Blank identifier discarding results; verify intentional ignoring of return values
warning correctness blank-identifier-discard
_ = flags.String("gen", "", "test")
Blank identifier discarding results; verify intentional ignoring of return values
warning correctness blank-identifier-discard
_ = flags.String("ci", "", "test")

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.