diff --git a/pkg/section/local_module.go b/pkg/section/local_module.go index 5af74b3..50f41e5 100644 --- a/pkg/section/local_module.go +++ b/pkg/section/local_module.go @@ -18,7 +18,7 @@ type LocalModule struct { } func (m *LocalModule) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity { - if strings.HasPrefix(spec.Path, m.Path) { + if spec.Path == m.Path || strings.HasPrefix(spec.Path, m.Path+"/") { return specificity.LocalModule{} } diff --git a/pkg/section/local_module_test.go b/pkg/section/local_module_test.go new file mode 100644 index 0000000..93702bf --- /dev/null +++ b/pkg/section/local_module_test.go @@ -0,0 +1,18 @@ +package section + +import ( + "testing" + + "github.com/daixiang0/gci/pkg/specificity" +) + +func TestLocalModule_specificity(t *testing.T) { + testCases := []specificityTestData{ + {"example.com/hello", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}}, + {"example.com/hello/world", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}}, + {"example.com/hello-world", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}}, + {"example.com/helloworld", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}}, + {"example.com", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}}, + } + testSpecificity(t, testCases) +}