cvs commit: qpsmtpd/t qpsmtpd-address.t

[email protected] (Ask "Bj?rn" Hansen)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/07/15 19:51:39

  Modified:    lib/Qpsmtpd Address.pm
               t        qpsmtpd-address.t
  Log:
  100% test coverage of Qpsmtpd::Address
  
  Revision  Changes    Path
  1.2       +4 -3      qpsmtpd/lib/Qpsmtpd/Address.pm
  
  Index: Address.pm
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/lib/Qpsmtpd/Address.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- Address.pm	15 Jul 2004 22:52:53 -0000	1.1
  +++ Address.pm	16 Jul 2004 02:51:39 -0000	1.2
  @@ -126,14 +126,15 @@
       $path = $1;
   
       # strip source route
  -    $path =~ s/[EMAIL PROTECTED](?:,[EMAIL PROTECTED])*://;
  +    $path =~ s/^\@$domain(?:,\@$domain)*://;
   
       # empty path is ok
       return "" if $path eq "";
   
       # 
       my ($localpart, $domainpart) = ($path =~ /^(.*)\@($domain)$/);
  -    return undef unless (defined $localpart && defined $domainpart);
  +    return undef unless defined $localpart;
  +
       if ($localpart =~ /^$atom(\.$atom)*/) {
           # simple case, we are done
           return $path;
  @@ -158,7 +159,7 @@
   sub address {
       my ($self, $val) = @_;
       my $oldval = $self->[0];
  -    $self->[0] = $val if (defined($val));
  +    return $self->[0] = $val if (defined($val));
       return $oldval;
   }
   
  
  
  
  1.3       +27 -2     qpsmtpd/t/qpsmtpd-address.t
  
  Index: qpsmtpd-address.t
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/t/qpsmtpd-address.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- qpsmtpd-address.t	16 Jul 2004 02:22:27 -0000	1.2
  +++ qpsmtpd-address.t	16 Jul 2004 02:51:39 -0000	1.3
  @@ -2,7 +2,7 @@
   use strict;
   use warnings;
   
  -use Test::More tests => 11;
  +use Test::More tests => 21;
   
   BEGIN {
       use_ok('Qpsmtpd::Address');
  @@ -21,6 +21,9 @@
   ok ($ao, "parse $as");
   is ($ao->format, $as, "format $as");
   
  +is ($ao->user, 'foo', 'user');
  +is ($ao->host, 'example.com', 'host');
  +
   # the \ before the @ in the local part is not required, but
   # allowed. For simplicity we add a backslash before all characters 
   # which are not allowed in a dot-string.
  @@ -37,8 +40,30 @@
   
   
   $as = '[email protected]';
  +$ao = Qpsmtpd::Address->parse($as);
  +is ($ao, undef, "can't parse $as");
  +
  +$as = '<@example.com>';
  +is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
  +
  +$as = '<@123>';
  +is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
  +
  +$as = '<user>';
  +is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
  +
  +
  +$as = '[email protected]';
   $ao = Qpsmtpd::Address->new($as);
  -ok ($ao, "parse $as");
  +ok ($ao, "new $as");
   is ($ao->address, $as, "address $as");
   
  +$as = '<[email protected]>';
  +$ao = Qpsmtpd::Address->new($as);
  +ok ($ao, "new $as");
  +is ($ao->address, '[email protected]', "address $as");
  +
  +# Not sure why we can change the address like this, but we can so test it ...
  +is ($ao->address('[email protected]'), '[email protected]', 'address([email protected])');
  +
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.