@@ 1,16 1,14 @@
-package fnmatch_test
+package fnmatch
import (
"testing"
-
- "github.com/danwakefield/fnmatch"
)
// This is a set of tests ported from a set of tests for C fnmatch
// found at http://www.mail-archive.com/bug-gnulib@gnu.org/msg14048.html
func TestMatch(t *testing.T) {
assert := func(p, s string) {
- if !fnmatch.Match(p, s, 0) {
+ if !Match(p, s, 0) {
t.Errorf("Assertion failed: Match(%#v, %#v, 0)", p, s)
}
}
@@ 25,7 23,7 @@ func TestMatch(t *testing.T) {
assert("foo*.txt", "foobar.txt")
assert("foo.txt", "foo.txt")
assert("foo\\.txt", "foo.txt")
- if fnmatch.Match("foo\\.txt", "foo.txt", fnmatch.FNM_NOESCAPE) {
+ if Match("foo\\.txt", "foo.txt", FNM_NOESCAPE) {
t.Errorf("Assertion failed: Match(%#v, %#v, FNM_NOESCAPE) == false", "foo\\.txt", "foo.txt")
}
}
@@ 47,10 45,10 @@ func TestWildcard(t *testing.T) {
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 70,26 68,26 @@ func TestWildcardSlash(t *testing.T) {
{"*", "/foo", 0, true},
{"*", "foo/", 0, true},
// Shouldnt match / when flags include FNM_PATHNAME
- {"*", "foo/bar", fnmatch.FNM_PATHNAME, false},
- {"*", "/", fnmatch.FNM_PATHNAME, false},
- {"*", "/foo", fnmatch.FNM_PATHNAME, false},
- {"*", "foo/", fnmatch.FNM_PATHNAME, false},
+ {"*", "foo/bar", FNM_PATHNAME, false},
+ {"*", "/", FNM_PATHNAME, false},
+ {"*", "/foo", FNM_PATHNAME, false},
+ {"*", "foo/", FNM_PATHNAME, false},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
}
for _, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Match('%s', '%s', %d) should be %v not %v",
c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 104,16 102,16 @@ func TestWildcardFNMPeriod(t *testing.T) {
flags int
want bool
}{
- {"*", ".foo", fnmatch.FNM_PERIOD, false},
- {"/*", "/.foo", fnmatch.FNM_PERIOD, true},
- {"/*", "/.foo", fnmatch.FNM_PERIOD | fnmatch.FNM_PATHNAME, false},
+ {"*", ".foo", FNM_PERIOD, false},
+ {"/*", "/.foo", FNM_PERIOD, true},
+ {"/*", "/.foo", FNM_PERIOD | FNM_PATHNAME, false},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 138,14 136,14 @@ func TestQuestionMark(t *testing.T) {
// Even '/' when flags are 0
{"?", "/", 0, true},
// Except '/' when flags include FNM_PATHNAME
- {"?", "/", fnmatch.FNM_PATHNAME, false},
+ {"?", "/", FNM_PATHNAME, false},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 160,17 158,17 @@ func TestQuestionMarkExceptions(t *testing.T) {
flags int
want bool
}{
- {"?", ".", fnmatch.FNM_PERIOD, false},
- {"foo?", "foo.", fnmatch.FNM_PERIOD, true},
- {"/?", "/.", fnmatch.FNM_PERIOD, true},
- {"/?", "/.", fnmatch.FNM_PERIOD | fnmatch.FNM_PATHNAME, false},
+ {"?", ".", FNM_PERIOD, false},
+ {"foo?", "foo.", FNM_PERIOD, true},
+ {"/?", "/.", FNM_PERIOD, true},
+ {"/?", "/.", FNM_PERIOD | FNM_PATHNAME, false},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 214,8 212,8 @@ func TestRange(t *testing.T) {
{"[a\\-z]", "b", 0, false},
// ignore '\\' when FNM_NOESCAPE is given
- {"[a\\-z]", "\\", fnmatch.FNM_NOESCAPE, true},
- {"[a\\-z]", "-", fnmatch.FNM_NOESCAPE, false},
+ {"[a\\-z]", "\\", FNM_NOESCAPE, true},
+ {"[a\\-z]", "-", FNM_NOESCAPE, false},
// Should be negated if starting with ^ or !"
{"[^a-z]", "a", 0, false},
@@ 237,23 235,23 @@ func TestRange(t *testing.T) {
//Should not match '/' when flags is FNM_PATHNAME
{"[abc/def]", "/", 0, true},
- {"[abc/def]", "/", fnmatch.FNM_PATHNAME, false},
+ {"[abc/def]", "/", FNM_PATHNAME, false},
{"[.-0]", "/", 0, true}, // The range [.-0] includes /
- {"[.-0]", "/", fnmatch.FNM_PATHNAME, false},
+ {"[.-0]", "/", FNM_PATHNAME, false},
// Should normally be case-sensitive
{"[a-z]", "A", 0, false},
{"[A-Z]", "a", 0, false},
//Except when FNM_CASEFOLD is given
- {"[a-z]", "A", fnmatch.FNM_CASEFOLD, true},
- {"[A-Z]", "a", fnmatch.FNM_CASEFOLD, true},
+ {"[a-z]", "A", FNM_CASEFOLD, true},
+ {"[A-Z]", "a", FNM_CASEFOLD, true},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 279,17 277,17 @@ func TestBackSlash(t *testing.T) {
{"\\わ", "わ", 0, true},
// Unless FNM_NOESCAPE is given
- {"\\\\", "\\", fnmatch.FNM_NOESCAPE, false},
- {"\\\\", "\\\\", fnmatch.FNM_NOESCAPE, true},
- {"\\*", "foo", fnmatch.FNM_NOESCAPE, false},
- {"\\*", "\\*", fnmatch.FNM_NOESCAPE, true},
+ {"\\\\", "\\", FNM_NOESCAPE, false},
+ {"\\\\", "\\\\", FNM_NOESCAPE, true},
+ {"\\*", "foo", FNM_NOESCAPE, false},
+ {"\\*", "\\*", FNM_NOESCAPE, true},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 310,15 308,15 @@ func TestLiteral(t *testing.T) {
{"foo", "Foo", 0, false},
{"わたし", "わたし", 0, true},
// And perform case-folding when FNM_CASEFOLD is given
- {"foo", "FOO", fnmatch.FNM_CASEFOLD, true},
- {"FoO", "fOo", fnmatch.FNM_CASEFOLD, true},
+ {"foo", "FOO", FNM_CASEFOLD, true},
+ {"FoO", "fOo", FNM_CASEFOLD, true},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}
@@ 334,16 332,16 @@ func TestFNMLeadingDir(t *testing.T) {
}{
// FNM_LEADING_DIR should ignore trailing '/*'
{"foo", "foo/bar", 0, false},
- {"foo", "foo/bar", fnmatch.FNM_LEADING_DIR, true},
- {"*", "foo/bar", fnmatch.FNM_PATHNAME, false},
- {"*", "foo/bar", fnmatch.FNM_PATHNAME | fnmatch.FNM_LEADING_DIR, true},
+ {"foo", "foo/bar", FNM_LEADING_DIR, true},
+ {"*", "foo/bar", FNM_PATHNAME, false},
+ {"*", "foo/bar", FNM_PATHNAME | FNM_LEADING_DIR, true},
}
for tc, c := range cases {
- got := fnmatch.Match(c.pattern, c.input, c.flags)
+ got := Match(c.pattern, c.input, c.flags)
if got != c.want {
t.Errorf(
- "Testcase #%d failed: fnmatch.Match('%s', '%s', %d) should be %v not %v",
+ "Testcase #%d failed: Match('%s', '%s', %d) should be %v not %v",
tc, c.pattern, c.input, c.flags, c.want, got,
)
}