Tinyglob: add function to match
This commit is contained in:
parent
a40d249fd6
commit
5fa70f72d8
2 changed files with 38 additions and 0 deletions
|
|
@ -49,4 +49,12 @@ sub tinyglob
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub match
|
||||||
|
{
|
||||||
|
my $glob = tinyglob(shift);
|
||||||
|
my $str = shift;
|
||||||
|
|
||||||
|
return $str =~ /$glob/;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,34 @@ is(Tinyglob::tinyglob("\\\\*"), "\\\\.*");
|
||||||
is(Tinyglob::tinyglob("\\?"), "\\?");
|
is(Tinyglob::tinyglob("\\?"), "\\?");
|
||||||
is(Tinyglob::tinyglob("\\\\?"), "\\\\.");
|
is(Tinyglob::tinyglob("\\\\?"), "\\\\.");
|
||||||
|
|
||||||
|
ok(! Tinyglob::match("?", ""));
|
||||||
|
ok(! Tinyglob::match("b", "a"));
|
||||||
|
ok(! Tinyglob::match("b*", "a"));
|
||||||
|
ok(! Tinyglob::match("b?", "a"));
|
||||||
|
ok(Tinyglob::match("*", ""));
|
||||||
|
|
||||||
|
ok(Tinyglob::match("a", "a"));
|
||||||
|
ok(Tinyglob::match("?", "a"));
|
||||||
|
ok(Tinyglob::match("*", "a"));
|
||||||
|
|
||||||
|
ok(Tinyglob::match("ab", "ab"));
|
||||||
|
ok(Tinyglob::match("?b", "ab"));
|
||||||
|
ok(Tinyglob::match("*b", "ab"));
|
||||||
|
ok(Tinyglob::match("*", "ab"));
|
||||||
|
|
||||||
|
ok(Tinyglob::match("b?", "ba"));
|
||||||
|
ok(Tinyglob::match("b*", "ba"));
|
||||||
|
ok(Tinyglob::match("*", "abcdef"));
|
||||||
|
|
||||||
|
ok(Tinyglob::match("a?b", "acb"));
|
||||||
|
ok(Tinyglob::match("a*b", "acb"));
|
||||||
|
ok(Tinyglob::match("a*b", "acdefb"));
|
||||||
|
|
||||||
|
ok(Tinyglob::match("a*b*", "acdefblkjgd"));
|
||||||
|
ok(! Tinyglob::match("a?b*", "acdefblkjgd"));
|
||||||
|
ok(Tinyglob::match("a?b*", "acblkjgd"));
|
||||||
|
ok(Tinyglob::match("a?b*", "abblkjgd"));
|
||||||
|
ok(! Tinyglob::match("a*b?", "abblkjgd"));
|
||||||
|
ok(Tinyglob::match("a*b?", "aasdasbd"));
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
||||||
Reference in a new issue