File: 05.misc.t

package info (click to toggle)
libperl-version-perl 1.018-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 2,327; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 1,902 bytes parent folder | download | duplicates (5)
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
73
74
75
76
77
#!/usr/bin/perl

use strict;
use warnings;
use Perl::Version;
use Test::More tests => 44;

package dummy;
sub new { return bless {}, shift }

package main;

my $v1 = Perl::Version->new();
isa_ok $v1, 'Perl::Version';

my $warned;
local $SIG{__WARN__} = sub { $warned = shift };

my %expect = (
  stringify  => 'v0.0.0',
  numify     => '0.000',
  components => '1',
  alpha      => 0,
  normal     => 'v0.0.0',
  revision   => 0,
  version    => undef,
  subversion => undef,
  is_alpha   => '',
);

while ( my ( $meth, $expect ) = each %expect ) {
  $warned = undef;
  my $result = eval { $v1->$meth };
  unless ( ok !$@, "$meth: no error" ) {
    diag( "Error was $@" );
  }
  unless ( ok !$warned, "$meth: no warning" ) {
    diag( "Warning was $@" );
  }
  is $result, $expect, "$meth: result OK";
}

my $v2 = Perl::Version->new( '5.8.8' );
is "$v2", '5.8.8', 'stringify overload OK';
my $v3 = $v2->new();
is "$v3", 'v0.0.0', 'new as method yields empty object';
my $v4 = $v3->new( $v2 );
is "$v4", '5.8.8', 'copy OK';

ok $v2 < 'v5.8.9', 'compare with string';
ok $v2 == 'v5.8.8', 'compare with string';
ok $v2 > 'v5.8.7', 'compare with string';
ok 'v5.8.9' > $v2, 'compare with string';
ok 'v5.8.8' == $v2, 'compare with string';
ok 'v5.8.7' < $v2, 'compare with string';

my $ar = [ 1, 2, 3 ];
$v3->components( $ar );
is "$v3", 'v1.2.3', 'set components from array';
$ar->[1]++;
is "$v3", 'v1.2.3', 'array copied rather than referenced';

eval { Perl::Version::new() };
like $@, qr/called.+method/, 'calling new as a function fails';

my $dummy = dummy->new;
eval { my $x = $v1 <=> $dummy };
like $@, qr/compare with/, 'compare to random object fails';

eval { my $x = $v1 <=> [] };
like $@, qr/compare with/, 'compare to hash ref fails';

eval { $v4->component };
like $@, qr/component number/, 'need component number';

eval { $v2->increment( 3 ) };
like $@, qr/out of range/, 'out of range';