go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/stringutil/glob_test.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package stringutil 9 10 import ( 11 "fmt" 12 "testing" 13 14 "go.charczuk.com/sdk/assert" 15 ) 16 17 func Test_Glob(t *testing.T) { 18 testCases := [...]struct { 19 Subj string 20 Pattern string 21 Expected bool 22 }{ 23 {"", "", true}, 24 {"test", "", false}, 25 {"", "false", false}, 26 {"", "*", true}, 27 {"foo", "*", true}, 28 {"bar", "*", true}, 29 30 {"bar/foo", "bar/*", true}, 31 {"foo/bar", "bar/*", false}, 32 33 {"bar/loo/foo", "bar/*", true}, 34 {"foo/bar/loo", "bar/*", false}, 35 36 {"foo/bar/baz/buzz", "*/bar/*", true}, 37 {"/foo/bar/baz/buzz", "*/bar/*", true}, 38 {"foo/bar/baz/buzz", "*/foo/*", false}, 39 {"foo/bar/baz/buzz", "foo/*", true}, 40 {"/foo/bar/baz/buzz", "*foo/*", true}, 41 {"test", "te*", true}, 42 {"test", "*st", true}, 43 {"test", "foo", false}, 44 {"test", "foo*", false}, 45 {"test", "*foo*", false}, 46 } 47 48 for _, testCase := range testCases { 49 assert.ItsEqual(t, testCase.Expected, Glob(testCase.Subj, testCase.Pattern), fmt.Sprint(testCase.Subj, " => ", testCase.Pattern)) 50 } 51 }