MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestRegexpFromPattern

Function TestRegexpFromPattern

env/types_test.go:637–676  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

635}
636
637func TestRegexpFromPattern(t *testing.T) {
638 tests := []struct {
639 pattern string
640 shouldMatch []string
641 shouldntMatch []string
642 }{
643 {
644 pattern: "test.jpg",
645 shouldMatch: []string{"test.jpg"},
646 shouldntMatch: []string{"test2.jpg"},
647 },
648 {
649 pattern: "*.jpg",
650 shouldMatch: []string{"image.jpg", "photo123.jpg"},
651 shouldntMatch: []string{"dir/image.jpg"},
652 },
653 {
654 pattern: "*-*-*.jpg",
655 shouldMatch: []string{"img-01-thumb.jpg"},
656 shouldntMatch: []string{"img-01.jpg"},
657 },
658 {
659 pattern: "prefix*",
660 shouldMatch: []string{"prefix123"},
661 shouldntMatch: []string{"notprefix"},
662 },
663 }
664
665 for _, tt := range tests {
666 t.Run(tt.pattern, func(t *testing.T) {
667 re := env.RegexpFromPattern(tt.pattern)
668 for _, match := range tt.shouldMatch {
669 assert.True(t, re.MatchString(match))
670 }
671 for _, noMatch := range tt.shouldntMatch {
672 assert.False(t, re.MatchString(noMatch))
673 }
674 })
675 }
676}
677
678func TestParseExistingFile(t *testing.T) {
679 d := testutil.NewTestDataProvider(func() *testing.T { return t })

Callers

nothing calls this directly

Calls 2

RegexpFromPatternFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected