405af07859
This reverts commit 323dc60712
.
Reason for revert: Possible cause of test instability
Bug: 170513220
Test: soong tests
Change-Id: Iee168e9fbb4210569e6cffcc23e60d111403abb8
158 lines
3.7 KiB
Go
158 lines
3.7 KiB
Go
// 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)
|
|
}
|
|
})
|
|
}
|
|
}
|