Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simple email validation tests

  • Loading branch information...
commit 7bc7810904f77945b9bc3966f040f81a6481c17b 1 parent 74a3bc3
@adrianoldham adrianoldham authored committed
Showing with 19 additions and 1 deletion.
  1. +19 −1 t/010-modules/020-validate.t
View
20 t/010-modules/020-validate.t
@@ -1,6 +1,6 @@
#!perl -w
use strict;
-use Test::More tests => 82;
+use Test::More tests => 88;
BEGIN { use_ok('DevHelp::Validate'); }
@@ -312,3 +312,21 @@ BEGIN { use_ok('DevHelp::Validate'); }
}
}
}
+
+# emails
+{
+ my $val = DevHelp::Validate::Hash->new
+ (
+ fields =>
+ {
+ email => { rules => "email" },
+ }
+ );
+ my %errors;
+ ok($val->validate({email => 'a@example.com' }, \%errors), 'a@example.com');
+ ok($val->validate({email => 'a+b@example.com' }, \%errors), 'a+b@example.com');
+ ok($val->validate({email => '"a b"@example.com' }, \%errors), '"a b"@example.com');
+ ok(!$val->validate({email => ' a@example.com' }, \%errors), "emails cannot begin with whitespace ");
+ ok(!$val->validate({email => ' a+b@example.com' }, \%errors), "emails cannot begin with whitespace");
+ ok(!$val->validate({email => ' "a b"@example.com' }, \%errors), "emails cannot begin with whitespace");
+}
Please sign in to comment.
Something went wrong with that request. Please try again.