Skip to content

Commit

Permalink
Add tests to make sure we're skipping validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemassa authored and bmatcuk committed Jan 25, 2025
1 parent 3b1e3d1 commit 569c123
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doublestar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,29 @@ func TestMatchUnvalidated(t *testing.T) {
for idx, tt := range matchTests {
testMatchUnvalidatedWith(t, idx, tt)
}
// Not only test that they get the right matches, but make sure Unvalidated is properly *skipping* validation

unvalidatedTests := []struct {
pattern, testPath string // a pattern and path to test the pattern on
expectedErrValidated error // the error expected if the pattern was being validated
expectedErrUnvalidated error // the error expected if the pattern was not being validated
}{
{"", "", nil, nil},
{"*", "", nil, nil},
{"a[", "a", ErrBadPattern, nil}, // End early because got to end of match; do not need to validate the rest
{"a[", "b", ErrBadPattern, nil}, // End early because failed to match; do not need to validate the rest
{"[", "a", ErrBadPattern, ErrBadPattern}, // Error right up front, needs to fail whether validate or not
}
for idx, tt := range unvalidatedTests {
_, errValidated := matchWithSeparator(tt.pattern, tt.testPath, '/', true)
_, errUnvalidated := matchWithSeparator(tt.pattern, tt.testPath, '/', false)
if errValidated != tt.expectedErrValidated {
t.Errorf("#%v. Validated error of Match(%#q, %#q) = %v want %v", idx, tt.pattern, tt.testPath, errValidated, tt.expectedErrValidated)
}
if errUnvalidated != tt.expectedErrUnvalidated {
t.Errorf("#%v. Unvalidated error of Match(%#q, %#q) = %v want %v", idx, tt.pattern, tt.testPath, errUnvalidated, tt.expectedErrUnvalidated)
}
}
}

func testMatchUnvalidatedWith(t *testing.T, idx int, tt MatchTest) {
Expand Down

0 comments on commit 569c123

Please sign in to comment.