@@ -348,13 +348,21 @@ func TestLinterSettingsCompile(t *testing.T) {
348
348
349
349
var (
350
350
prefixList = []string {
351
- "some/package/a" ,
352
- "some/package/b" ,
353
- "some/package/c/" ,
354
- "some/package/d$" ,
355
- "some/pkg/c" ,
356
- "some/pkg/d" ,
357
- "some/pkg/e" ,
351
+ "willd.io/package/a" ,
352
+ "willd.io/package/b" ,
353
+ "willd.io/package/c/" ,
354
+ "willd.io/package/d$" ,
355
+ "willd.io/pkg/c" ,
356
+ "willd.io/pkg/d" ,
357
+ "willd.io/pkg/e" ,
358
+ }
359
+
360
+ diffKindsList = []string {
361
+ "./relative/path" ,
362
+ "/absolute/path" ,
363
+ "os/exec" ,
364
+ "path" ,
365
+ "willd.io/normal/package" ,
358
366
}
359
367
360
368
globList = []glob.Glob {
@@ -375,19 +383,53 @@ func testStrInPrefixList(str string, expect bool, expectedIdx int) func(t *testi
375
383
}
376
384
}
377
385
386
+ func testStrInDiffPrefixList (str string , expect bool , expectedIdx int ) func (t * testing.T ) {
387
+ return func (t * testing.T ) {
388
+ act , idx := strInPrefixList (str , diffKindsList )
389
+ if act != expect {
390
+ t .Errorf ("string prefix mismatch: expected %s - got %s" , strconv .FormatBool (expect ), strconv .FormatBool (act ))
391
+ }
392
+ if idx != expectedIdx {
393
+ t .Errorf ("string prefix index: expected %d - got %d" , expectedIdx , idx )
394
+ }
395
+ }
396
+ }
397
+
378
398
func TestStrInPrefixList (t * testing.T ) {
379
399
sort .Strings (prefixList )
380
- t .Run ("full_match_start" , testStrInPrefixList ("some/package/a" , true , 0 ))
381
- t .Run ("full_match" , testStrInPrefixList ("some/package/b" , true , 1 ))
382
- t .Run ("full_match_end" , testStrInPrefixList ("some/pkg/e" , true , 6 ))
383
- t .Run ("no_match_end" , testStrInPrefixList ("zome/pkg/e" , false , 6 ))
384
- t .Run ("no_match_start" , testStrInPrefixList ("aome/pkg/e" , false , - 1 ))
385
- t .Run ("match_start" , testStrInPrefixList ("some/package/a/files" , true , 0 ))
386
- t .Run ("match_middle" , testStrInPrefixList ("some/pkg/c/files" , true , 4 ))
387
- t .Run ("match_end" , testStrInPrefixList ("some/pkg/e/files" , true , 6 ))
388
- t .Run ("no_match_trailing" , testStrInPrefixList ("some/package/c" , false , 1 ))
389
- t .Run ("match_exact" , testStrInPrefixList ("some/package/d" , true , 3 ))
390
- t .Run ("no_prefix_match_exact" , testStrInPrefixList ("some/package/d/something" , false , 3 ))
400
+ t .Run ("full_match_start" , testStrInPrefixList ("willd.io/package/a" , true , 0 ))
401
+ t .Run ("full_match" , testStrInPrefixList ("willd.io/package/b" , true , 1 ))
402
+ t .Run ("full_match_end" , testStrInPrefixList ("willd.io/pkg/e" , true , 6 ))
403
+ t .Run ("no_match_end" , testStrInPrefixList ("zilld.io/pkg/e" , false , 6 ))
404
+ t .Run ("no_match_start" , testStrInPrefixList ("ailld.io/pkg/e" , false , - 1 ))
405
+ t .Run ("match_start" , testStrInPrefixList ("willd.io/package/a/files" , true , 0 ))
406
+ t .Run ("match_middle" , testStrInPrefixList ("willd.io/pkg/c/files" , true , 4 ))
407
+ t .Run ("match_end" , testStrInPrefixList ("willd.io/pkg/e/files" , true , 6 ))
408
+ t .Run ("no_match_trailing" , testStrInPrefixList ("willd.io/package/c" , false , 1 ))
409
+ t .Run ("match_exact" , testStrInPrefixList ("willd.io/package/d" , true , 3 ))
410
+ t .Run ("no_prefix_match_exact" , testStrInPrefixList ("willd.io/package/d/something" , false , 3 ))
411
+
412
+ sort .Strings (diffKindsList )
413
+ t .Run ("match_import_with_domain_exact" , testStrInDiffPrefixList ("willd.io/normal/package" , true , 4 ))
414
+ t .Run ("match_import_with_domain" , testStrInDiffPrefixList ("willd.io/normal/package/nested" , true , 4 ))
415
+ t .Run ("no_match_import_with_domain" , testStrInDiffPrefixList ("willd.io/normal" , false , 3 ))
416
+ t .Run ("match_import_relative_exact" , testStrInDiffPrefixList ("./relative/path" , true , 0 ))
417
+ t .Run ("match_import_relative" , testStrInDiffPrefixList ("./relative/path/nested" , true , 0 ))
418
+ t .Run ("no_match_import_relative" , testStrInDiffPrefixList ("./relative" , false , - 1 ))
419
+ t .Run ("match_import_absolute_exact" , testStrInDiffPrefixList ("/absolute/path" , true , 1 ))
420
+ t .Run ("match_import_absolute" , testStrInDiffPrefixList ("/absolute/path/nested" , true , 1 ))
421
+ t .Run ("no_match_import_absolute" , testStrInDiffPrefixList ("/absolute" , false , 0 ))
422
+ t .Run ("match_gostd_single_exact" , testStrInDiffPrefixList ("path" , true , 3 ))
423
+ t .Run ("match_gostd_single" , testStrInDiffPrefixList ("path/filepath" , true , 3 ))
424
+ t .Run ("no_match_gostd_single" , testStrInDiffPrefixList ("evil" , false , 1 ))
425
+ t .Run ("match_gostd_multiple_exact" , testStrInDiffPrefixList ("os/exec" , true , 2 ))
426
+ t .Run ("match_gostd_multiple" , testStrInDiffPrefixList ("os/exec/fake" , true , 2 ))
427
+ t .Run ("no_match_gostd_multiple" , testStrInDiffPrefixList ("os/evil" , false , 1 ))
428
+
429
+ // "Evil Packages"
430
+ t .Run ("gostd_in_domain" , testStrInDiffPrefixList ("path.willd.io/normal/package" , false , 3 ))
431
+ t .Run ("gostd_in_relative" , testStrInDiffPrefixList ("./os/exec" , false , - 1 ))
432
+ t .Run ("gostd_in_absolute" , testStrInDiffPrefixList ("/os/exec" , false , 1 ))
391
433
}
392
434
393
435
func testStrInGlobList (str string , expect bool ) func (t * testing.T ) {
0 commit comments