[libcode-tidyall-perl] 79/374: test zglob_to_regex
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:25:52 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit 8160e9fcbd7b13afe547c6e1b20e6f66076bb83b
Author: Jonathan Swartz <swartz at pobox.com>
Date: Fri Jul 6 02:47:24 2012 -0700
test zglob_to_regex
---
lib/Code/TidyAll/Util/Zglob.pm | 12 ++----------
lib/Code/TidyAll/t/Zglob.pm | 33 +++++++++++++++++++++++++++++++++
t/Zglob.t | 3 +++
3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/lib/Code/TidyAll/Util/Zglob.pm b/lib/Code/TidyAll/Util/Zglob.pm
index 5c7531d..6dae62e 100644
--- a/lib/Code/TidyAll/Util/Zglob.pm
+++ b/lib/Code/TidyAll/Util/Zglob.pm
@@ -16,11 +16,11 @@ use constant debug => 0;
sub zglob_to_regex {
my $glob = shift;
- my $regex = glob_to_regex_string($glob);
+ my $regex = zglob_to_regex_string($glob);
return qr/^$regex$/;
}
-sub glob_to_regex_string {
+sub zglob_to_regex_string {
my $glob = shift;
my ( $regex, $in_curlies, $escaping );
local $_;
@@ -98,13 +98,5 @@ sub glob_to_regex_string {
return $regex;
}
-sub match_glob {
- print "# ", join( ', ', map { "'$_'" } @_ ), "\n" if debug;
- my $glob = shift;
- my $regex = glob_to_regex $glob;
- local $_;
- grep { $_ =~ $regex } @_;
-}
-
1;
__END__
diff --git a/lib/Code/TidyAll/t/Zglob.pm b/lib/Code/TidyAll/t/Zglob.pm
new file mode 100644
index 0000000..ec1b869
--- /dev/null
+++ b/lib/Code/TidyAll/t/Zglob.pm
@@ -0,0 +1,33 @@
+package Code::TidyAll::t::Zglob;
+use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
+use Code::TidyAll::Util::Zglob qw(zglob_to_regex);
+
+sub test_match : Tests {
+ my ( $zglob, $regex );
+
+ $zglob = "**/*.txt";
+ $regex = zglob_to_regex($zglob);
+ foreach my $path qw(foo.txt foo/baz.txt foo/bar/baz.txt) {
+ like( $path, $regex, "$path matches $zglob" );
+ }
+ foreach my $path qw(foo/bar/baz.tx) {
+ unlike( $path, $regex, "$path does not match $zglob" );
+ }
+
+ $zglob = "**/*";
+ $regex = zglob_to_regex($zglob);
+ foreach my $path qw(foo foo.txt foo/bar foo/baz.txt) {
+ like( $path, $regex, "$path matches $zglob" );
+ }
+
+ $zglob = "foo/**/*.txt";
+ $regex = zglob_to_regex($zglob);
+ foreach my $path qw(foo/baz.txt foo/bar/baz.txt foo/bar/baz/blargh.txt) {
+ like( $path, $regex, "$path matches $zglob" );
+ }
+ foreach my $path qw(foo.txt foo/bar/baz.tx) {
+ unlike( $path, $regex, "$path does not match $zglob" );
+ }
+}
+
+1;
diff --git a/t/Zglob.t b/t/Zglob.t
new file mode 100644
index 0000000..606dfd0
--- /dev/null
+++ b/t/Zglob.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Zglob;
+Code::TidyAll::t::Zglob->runtests;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list