123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // Copyright 2019 Google Inc. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package main
- import (
- "testing"
- )
- func TestMatch(t *testing.T) {
- testCases := []struct {
- pattern, name string
- match bool
- }{
- {"a/*", "b/", false},
- {"a/*", "b/a", false},
- {"a/*", "b/b/", false},
- {"a/*", "b/b/c", false},
- {"a/**/*", "b/", false},
- {"a/**/*", "b/a", false},
- {"a/**/*", "b/b/", false},
- {"a/**/*", "b/b/c", false},
- {"a/*", "a/", false},
- {"a/*", "a/a", true},
- {"a/*", "a/b/", false},
- {"a/*", "a/b/c", false},
- {"a/*/", "a/", false},
- {"a/*/", "a/a", false},
- {"a/*/", "a/b/", true},
- {"a/*/", "a/b/c", false},
- {"a/**/*", "a/", false},
- {"a/**/*", "a/a", true},
- {"a/**/*", "a/b/", false},
- {"a/**/*", "a/b/c", true},
- {"a/**/*/", "a/", false},
- {"a/**/*/", "a/a", false},
- {"a/**/*/", "a/b/", true},
- {"a/**/*/", "a/b/c", false},
- {"**/*", "a/", false},
- {"**/*", "a/a", true},
- {"**/*", "a/b/", false},
- {"**/*", "a/b/c", true},
- {"**/*/", "a/", true},
- {"**/*/", "a/a", false},
- {"**/*/", "a/b/", true},
- {"**/*/", "a/b/c", false},
- {`a/\*\*/\*`, `a/**/*`, true},
- {`a/\*\*/\*`, `a/a/*`, false},
- {`a/\*\*/\*`, `a/**/a`, false},
- {`a/\*\*/\*`, `a/a/a`, false},
- {`a/**/\*`, `a/**/*`, true},
- {`a/**/\*`, `a/a/*`, true},
- {`a/**/\*`, `a/**/a`, false},
- {`a/**/\*`, `a/a/a`, false},
- {`a/\*\*/*`, `a/**/*`, true},
- {`a/\*\*/*`, `a/a/*`, false},
- {`a/\*\*/*`, `a/**/a`, true},
- {`a/\*\*/*`, `a/a/a`, false},
- {`*/**/a`, `a/a/a`, true},
- {`*/**/a`, `*/a/a`, true},
- {`*/**/a`, `a/**/a`, true},
- {`*/**/a`, `*/**/a`, true},
- {`\*/\*\*/a`, `a/a/a`, false},
- {`\*/\*\*/a`, `*/a/a`, false},
- {`\*/\*\*/a`, `a/**/a`, false},
- {`\*/\*\*/a`, `*/**/a`, true},
- {`a/?`, `a/?`, true},
- {`a/?`, `a/a`, true},
- {`a/\?`, `a/?`, true},
- {`a/\?`, `a/a`, false},
- {`a/?`, `a/?`, true},
- {`a/?`, `a/a`, true},
- {`a/\?`, `a/?`, true},
- {`a/\?`, `a/a`, false},
- {`a/[a-c]`, `a/b`, true},
- {`a/[abc]`, `a/b`, true},
- {`a/\[abc]`, `a/b`, false},
- {`a/\[abc]`, `a/[abc]`, true},
- {`a/\[abc\]`, `a/b`, false},
- {`a/\[abc\]`, `a/[abc]`, true},
- {`a/?`, `a/?`, true},
- {`a/?`, `a/a`, true},
- {`a/\?`, `a/?`, true},
- {`a/\?`, `a/a`, false},
- {"/a/*", "/a/", false},
- {"/a/*", "/a/a", true},
- {"/a/*", "/a/b/", false},
- {"/a/*", "/a/b/c", false},
- {"/a/*/", "/a/", false},
- {"/a/*/", "/a/a", false},
- {"/a/*/", "/a/b/", true},
- {"/a/*/", "/a/b/c", false},
- {"/a/**/*", "/a/", false},
- {"/a/**/*", "/a/a", true},
- {"/a/**/*", "/a/b/", false},
- {"/a/**/*", "/a/b/c", true},
- {"/**/*", "/a/", false},
- {"/**/*", "/a/a", true},
- {"/**/*", "/a/b/", false},
- {"/**/*", "/a/b/c", true},
- {"/**/*/", "/a/", true},
- {"/**/*/", "/a/a", false},
- {"/**/*/", "/a/b/", true},
- {"/**/*/", "/a/b/c", false},
- {`a`, `/a`, false},
- {`/a`, `a`, false},
- {`*`, `/a`, false},
- {`/*`, `a`, false},
- {`**/*`, `/a`, false},
- {`/**/*`, `a`, false},
- }
- for _, test := range testCases {
- t.Run(test.pattern+","+test.name, func(t *testing.T) {
- match, err := Match(test.pattern, test.name)
- if err != nil {
- t.Fatal(err)
- }
- if match != test.match {
- t.Errorf("want: %v, got %v", test.match, match)
- }
- })
- }
- }
|