Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanuber committed Feb 26, 2016
1 parent f80c139 commit 572520e
Showing 1 changed file with 57 additions and 14 deletions.
71 changes: 57 additions & 14 deletions glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,82 @@ func TestEmptyPattern(t *testing.T) {
}

func TestEmptySubject(t *testing.T) {
testGlobMatch(t, "", "")
testGlobNoMatch(t, "test", "")
testGlobMatch(t, "*", "")
testGlobMatch(t, "**", "")
testGlobMatch(t, "***", "")
testGlobMatch(t, "******************************", "")
testGlobMatch(t, strings.Repeat("*", 1000000), "")
testGlobNoMatch(t, strings.Repeat("*", 1000000)+"x", "")
testGlobNoMatch(t, "x"+strings.Repeat("*", 1000000), "")
testGlobNoMatch(t, "x"+strings.Repeat("*", 1000000)+"x", "")
for _, pattern := range []string{
"",
"*",
"**",
"***",
"****************",
strings.Repeat("*", 1000000),
} {
testGlobMatch(t, pattern, "")
}

for _, pattern := range []string{
// No globs/non-glob characters
"test",
"*test*",

// Trailing characters
"*x",
"*****************x",
strings.Repeat("*", 1000000) + "x",

// Leading characters
"x*",
"x*****************",
"x" + strings.Repeat("*", 1000000),

// Mixed leading/trailing characters
"x*x",
"x****************x",
"x" + strings.Repeat("*", 1000000) + "x",
} {
testGlobNoMatch(t, pattern, "")
}
}

func TestPatternWithoutGlobs(t *testing.T) {
testGlobMatch(t, "test", "test")
}

func TestGlob(t *testing.T) {
// Matches
for _, pattern := range []string{
"*test", // Leading glob
"this*", // Trailing glob
"this*test", // Middle glob
"*is *", // String in between two globs
"*is*a*", // Lots of globs
"**test**", // Double glob characters
"**is**a***test*", // Varying number of globs
"* *", // White space between globs
"*", // Lone glob
"**********", // Nothing but globs
"*Ѿ*", // Unicode with globs
"*is a ϗѾ *", // Mixed ASCII/unicode
} {
testGlobMatch(t, pattern, "this is a test")
testGlobMatch(t, pattern, "this is a ϗѾ test")
}

// Non-matches
for _, pattern := range []string{
"test*", // Implicit substring match should fail
"*is", // Partial match should fail
"*no*", // Globs without a match between them should fail
"test*", // Implicit substring match
"*is", // Partial match
"*no*", // Globs without a match between them
" ", // Plain white space
"* ", // Trailing white space
" *", // Leading white space
"*ʤ*", // Non-matching unicode
} {
testGlobNoMatch(t, pattern, "this is a test")
}
}

func BenchmarkGlob(b *testing.B) {
for i := 0; i < b.N; i++ {
if !Glob("*quick*fox*dog", "The quick brown fox jumped over the lazy dog") {
b.Fatalf("should match")
}
}
}

0 comments on commit 572520e

Please sign in to comment.