File: 1.t

package info (click to toggle)
libmail-verp-perl 0.06%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 68 kB
  • ctags: 6
  • sloc: perl: 81; makefile: 39
file content (72 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'

#########################


use Test;
BEGIN { plan tests => 122 };
use Mail::Verp;
ok(1); # If we made it this far, we're ok.

#########################

my $x = Mail::Verp->new;

ok(defined($x) && $x->isa('Mail::Verp'));


my $sender = 'local@source.com';
my @recipients = (
  'standard@example.com', [qw(local standard=example.com@source.com)],
  'remote+foo@example.com',  [qw(local remote+2Bfoo=example.com@source.com)],
  'node42!ann@old.example.com', [qw(local node42+21ann=old.example.com@source.com)],
  '=@example.com', [qw(local ==example.com@source.com)],
);

=pod

print STDERR "$s $r1 encodes -> ", $x->encode($s, $r1), "\n";
print STDERR "$s $r2 encodes -> ", $x->encode($s, $r2), "\n";

=cut

#Test various address types
for (my $i = 0; $i < @recipients; $i += 2) {
  my ($recipient, $verp) = @recipients[$i, $i+1];

  #test various separators, including default separator
  for my $sep (undef, qw(- +)) {

    #test use of object method and class method calls.
    my @refs = ('object' => $x, 'class' => 'Mail::Verp');

    for (my $j = 0; $j < @refs; $j += 2) {
      my ($encoder_name, $encoder) = @refs[$j, $j+1];

      my $expected = join(defined($sep) ? $sep : $encoder->separator, @$verp);
      $encoder->separator($sep) if defined $sep;
      
      my $sep_str = $sep || '';

      my $encoded = $encoder->encode($sender, $recipient);

      ok($encoded, $expected,
         "encoded address using $encoder_name instance with separator [$sep_str]");

      #decode each encoding with both an object and class method call.
      for (my $k = 0; $k < @refs; $k += 2) {
        my ($decoder_name, $decoder) = @refs[$k, $k+1];

        $decoder->separator($sep) if defined $sep;
        my ($decoded_sender, $decoded_recipient) = $decoder->decode($encoded);

        ok($decoded_sender, $sender,
          "encoded with $encoder_name and separator [$sep_str], decoded sender with $decoder_name");

        ok($decoded_recipient, $recipient,
          "encoded with $encoder_name and separator [$sep_str], decoded recipient with $decoder_name");
      }
    }
  }
}