summaryrefslogtreecommitdiffstats
path: root/tests/002-rpmvercmp.phpt
blob: c53a1836164d08fc964e0696ff90e333368c151b (plain)
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
--TEST--
Check for rpmvercmp function
--SKIPIF--
<?php if (!extension_loaded("rpminfo")) print "skip"; ?>
--FILE--
<?php
$cases = [
	['1.0', '1.1', -1],
	['1.1', '1.0', 1],
	['1.0', '1.0', 0],
	['1.0', '1', 1],
	['1', '1.1', -1],
	['2.0.14-22.el7_0', '2.0.14.1-35.el7_6', -1],
	['', '', 0],
	['0:1', '1', 0],
	['0:1', '1:1', -1],
	['1:1', '2', 1],
	['1~RC1', '1', -1],
	['1~RC1', '1', -1],
	['1~RC1-1', '1-0', -1],
	['1~beta', '1~RC', 1],
	['1-1', '1-2', -1],
	['1.1-1', '1-1.1', 1],
	['1.1-1~a', '1.1-1', -1],
	['1.2.3-4', '1.2.3p1-2', -1],
	['1.2.3-4', '1.2.3+a-2', -1],
];
$ok = true;
foreach ($cases as $case) {
	list($a,$b,$expected) = $case;
	$result = rpmvercmp($a,$b);
	if ($result !== $expected) {
		$ok = false;
		printf("rpmvercmp(%s, %s) = %d when %d expected\n", $a, $b, $result, $expected);
	}
}

$cases = [
	['1', '2', '>',  false],
	['1', '2', 'gt', false],
	['1', '2', '>=', false],
	['1', '2', 'ge', false],
	['1', '1', '>=', true],
	['1', '1', 'ge', true],

	['1', '2', '<',  true],
	['1', '2', 'lt', true],
	['1', '2', '<=', true],
	['1', '2', 'le', true],
	['1', '1', '<=', true],
	['1', '1', 'le', true],

	['1', '1', '=', true],
	['1', '1', '==', true],
	['1', '1', 'eq', true],

	['1', '2', '=',  false],
	['1', '2', '==', false],
	['1', '2', 'eq', false],

	['1', '1', '!=', false],
	['1', '1', '<>', false],
	['1', '1', 'ne', false],

	['1', '2', '!=', true],
	['1', '2', '<>', true],
	['1', '2', 'ne', true],
];
foreach ($cases as $case) {
	list($a,$b,$op,$expected) = $case;
	$result = rpmvercmp($a,$b,$op);
	if ($result !== $expected) {
		$ok = false;
		printf("rpmvercmp(%s, %s, %s) = %s when %s expected\n",
			$a, $b, $op, $result ? "true" : "false", $expected ? "true" : "false");
	}
}

if ($ok) echo "OK\n";
?>
Done
--EXPECTF--
OK
Done