simple email validation tests
authorAdrian Oldham <adriann@visualthought.com.au>
Tue, 25 Feb 2014 00:40:52 +0000 (11:40 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 25 Feb 2014 23:00:08 +0000 (10:00 +1100)
t/010-modules/020-validate.t

index 28ccab6d65b392764a1d6a7b804da31ead70d5c8..88001658ae9f46592f2b1545c49a2e813766024b 100644 (file)
@@ -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");
+}