github.com/daixiang0/gci@v0.13.4/pkg/section/section_test.go (about) 1 package section 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/daixiang0/gci/pkg/parse" 8 "github.com/daixiang0/gci/pkg/specificity" 9 ) 10 11 type specificityTestData struct { 12 path string 13 section Section 14 expectedSpecificity specificity.MatchSpecificity 15 } 16 17 func testSpecificity(t *testing.T, testCases []specificityTestData) { 18 for _, test := range testCases { 19 testName := fmt.Sprintf("%s:%v", test.path, test.section) 20 t.Run(testName, testSpecificityCase(test)) 21 } 22 } 23 24 func testSpecificityCase(testData specificityTestData) func(t *testing.T) { 25 return func(t *testing.T) { 26 t.Parallel() 27 detectedSpecificity := testData.section.MatchSpecificity(&parse.GciImports{Path: testData.path}) 28 if detectedSpecificity != testData.expectedSpecificity { 29 t.Errorf("Specificity is %v and not %v", detectedSpecificity, testData.expectedSpecificity) 30 } 31 } 32 }