summaryrefslogtreecommitdiff
path: root/t/lib/PVTests/Regex.pm
diff options
context:
space:
mode:
Diffstat (limited to 't/lib/PVTests/Regex.pm')
-rw-r--r--t/lib/PVTests/Regex.pm85
1 files changed, 85 insertions, 0 deletions
diff --git a/t/lib/PVTests/Regex.pm b/t/lib/PVTests/Regex.pm
new file mode 100644
index 0000000..3075427
--- /dev/null
+++ b/t/lib/PVTests/Regex.pm
@@ -0,0 +1,85 @@
+package PVTests::Regex;
+
+use strict;
+use warnings;
+
+use Params::Validate qw(:all);
+
+use PVTests;
+use Test::More;
+
+sub run_tests {
+ plan tests => 7;
+
+ eval {
+ my @a = ( foo => 'bar' );
+ validate( @a, { foo => { regex => '^bar$' } } );
+ };
+ is( $@, q{} );
+
+ eval {
+ my @a = ( foo => 'bar' );
+ validate( @a, { foo => { regex => qr/^bar$/ } } );
+ };
+ is( $@, q{} );
+
+ eval {
+ my @a = ( foo => 'baz' );
+ validate( @a, { foo => { regex => '^bar$' } } );
+ };
+
+ if ( $ENV{PERL_NO_VALIDATION} ) {
+ is( $@, q{} );
+ }
+ else {
+ like( $@, qr/'foo'.+did not pass regex check/ );
+ }
+
+ eval {
+ my @a = ( foo => 'baz' );
+ validate( @a, { foo => { regex => qr/^bar$/ } } );
+ };
+
+ if ( $ENV{PERL_NO_VALIDATION} ) {
+ is( $@, q{} );
+ }
+ else {
+ like( $@, qr/'foo'.+did not pass regex check/ );
+ }
+
+ eval {
+ my @a = ( foo => 'baz', bar => 'quux' );
+ validate(
+ @a, {
+ foo => { regex => qr/^baz$/ },
+ bar => { regex => 'uqqx' },
+ }
+ );
+ };
+
+ if ( $ENV{PERL_NO_VALIDATION} ) {
+ is( $@, q{} );
+ }
+ else {
+ like( $@, qr/'bar'.+did not pass regex check/ );
+ }
+
+ eval {
+ my @a = ( foo => 'baz', bar => 'quux' );
+ validate(
+ @a, {
+ foo => { regex => qr/^baz$/ },
+ bar => { regex => qr/^(?:not this|quux)$/ },
+ }
+ );
+ };
+ is( $@, q{} );
+
+ eval {
+ my @a = ( foo => undef );
+ validate( @a, { foo => { regex => qr/^$|^bubba$/ } } );
+ };
+ is( $@, q{} );
+}
+
+1;