-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug: matching pattern like *head with string like head_hello will…
… panic
- Loading branch information
1 parent
d30d557
commit 889ca1c
Showing
2 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package util | ||
|
||
import "testing" | ||
|
||
func TestWildMatcher(t *testing.T) { | ||
m := NewWildcardMatcher("*decode*,*hello*", '?', true) | ||
b := m.Match("this_is_a_decode_name") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("this_is_a_hello_name") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("this_is_a_name") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("decode") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("hello") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("hellodecode") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
} | ||
func TestWildMatcherHead(t *testing.T) { | ||
m := NewWildcardMatcher("*decode", '?', true) | ||
b := m.Match("decode_name") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("jgq_decode") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
} | ||
func TestWildMatcherTail(t *testing.T) { | ||
m := NewWildcardMatcher("decode*", '?', true) | ||
b := m.Match("decode_name") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("jgq_decode") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
} | ||
func TestEmptyMatcher(t *testing.T) { | ||
m := NewWildcardMatcher("", '?', false) | ||
b := m.Match("") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
b = m.Match("hello") | ||
if b { | ||
t.Fatalf("fail match") | ||
} | ||
m = NewWildcardMatcher("", '?', true) | ||
b = m.Match("") | ||
if !b { | ||
t.Fatalf("fail match") | ||
} | ||
} |