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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  | 
#!/usr/bin/perl
#$Id: versions.t,v 1.9 2003/08/24 22:33:03 ed Exp $
use 5.006;
use strict;
use warnings;
use Sort::Versions;
use Test::More;
my @tests;
while(<DATA>) {
	if(/^\s*(\S+)\s*([<>])\s*(\S+)\s*$/) {
		push @tests, $1,$3 if $2 eq "<";
		push @tests, $3,$1 if $2 eq ">";
	}
}
plan tests => (@tests / 2 * 3) + 3;
my @l = sort versions qw(1.2 1.2a);
is($l[0], "1.2");
@l = sort { versioncmp($a, $b) } qw(1.2 1.2a);
is($l[0], "1.2");
SKIP: {
    skip "requires perl 5.6.0", 1 unless ($] >= 5.006);
    @l = sort versioncmp qw(1.2 1.2a);
    is($l[0], "1.2");
}
my $i=4;
while (@tests) {
    ($a, $b) = @tests[0, 1];
    # Test both the versioncmp() and versions() interfaces, in both
    # the main package and other packages.
    #
    is(versions(), -1, "versions($a, $b)");
    $i++;
    is(versioncmp($a, $b), -1, "versioncmp($a, $b)");
    $i++;
	
    undef $a; undef $b; # just in case
	
    eval {
	package Foo;
	use Sort::Versions;
	($a, $b) = @tests[0, 1];
        if (versions() != -1) {
	    die "failed versions() in foreign package";
	}
        if (versioncmp($a, $b) != -1) {
	    die "failed versioncmp() in foreign package";
	}
    };
    if ($@) {
	fail($@);
    }
    else {
	pass("foreign package tests ($tests[0], $tests[1])");
    }
    shift @tests; shift @tests;
}
__END__
# Simple . only tests
1.2   < 1.3
1.2   < 1.2.1
1.2.1 < 1.3
1.2   < 1.2a
1.2a  < 1.3
1.2   < 1.2.b
1.2.1 < 1.2a
1.2.b < 1.2a
# Assorted non-numerics
a     < b
a     < a.b
a.b   < a.c
a.1   < a.a
1 < a
1a < a
1a < 2
# Null version point
1..1 < 1.1.1
# Leading 0 tests
1 > 0002
1.5 > 1.06
# Handling mixed -. versions
1 < 1-1
1-1 < 1-2
1-2 < 1.2
1-2 < 1.0-1
1-2 < 1.0
1-2 < 1.3
1.2-1 < 1.2a-1
1.3-4.6-7 < 1.3-4.8
1.3-4.6-7 < 1.3-4.6.7
1.3-4a-7 < 1.3-4a-7.4
# 'Bug' reported by pgw99
1.2-1 < 1.2.1-1
1.2.1-1 < 1.2.1-2
1.2.1-2 < 1.3.0-1
  |