66 "github.com/stretchr/testify/assert"
77
88 . "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/coverage"
9+ "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/path"
910)
1011
1112func TestCoveredPercentage (t * testing.T ) {
@@ -28,3 +29,39 @@ func TestCoveredPercentage(t *testing.T) {
2829 assert .Equal (t , tc .percentage , CoveredPercentage (tc .total , tc .covered ))
2930 }
3031}
32+
33+ func TestStripPrefix (t * testing.T ) {
34+ t .Parallel ()
35+
36+ tests := []struct {
37+ file string
38+ prefix string
39+ noPrefix string
40+ }{
41+ {
42+ file : path .Normalize ("github.com/example/foo/bar.go" ),
43+ prefix : "github.com/example" ,
44+ noPrefix : path .Normalize ("foo/bar.go" ),
45+ },
46+ {
47+ file : path .Normalize ("github.com/example/foo/bar.go" ),
48+ prefix : "github.com/example/" ,
49+ noPrefix : path .Normalize ("foo/bar.go" ),
50+ },
51+ {
52+ file : path .Normalize ("github.com/example/foo/bar.go" ),
53+ prefix : "example/foo" ,
54+ noPrefix : path .Normalize ("bar.go" ),
55+ },
56+ {
57+ file : path .Normalize ("github.com/example/foo/bar.go" ),
58+ prefix : "github.com/example1/" ,
59+ noPrefix : path .Normalize ("github.com/example/foo/bar.go" ),
60+ },
61+ }
62+
63+ for _ , tc := range tests {
64+ name := StripPrefix (tc .file , tc .prefix )
65+ assert .Equal (t , tc .noPrefix , name )
66+ }
67+ }
0 commit comments