diff options
author | Remi Collet <remi@remirepo.net> | 2023-09-11 10:21:36 +0200 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2023-09-11 10:21:36 +0200 |
commit | 64504e8b8fb097d6e849953eb0e4721321c41a27 (patch) | |
tree | 6d993631f655de280efa8b6db1c664f0294ae39b /tests | |
parent | 1662502e7dc10dcd4f17eb304486e2058cbb1d5a (diff) |
add optional operator to rpmcmpver for consistency with version_compare
Diffstat (limited to 'tests')
-rw-r--r-- | tests/002-rpmvercmp.phpt | 44 | ||||
-rw-r--r-- | tests/010-rpmvercmp_error7.phpt | 10 | ||||
-rw-r--r-- | tests/011-rpmvercmp_error8.phpt | 12 |
3 files changed, 59 insertions, 7 deletions
diff --git a/tests/002-rpmvercmp.phpt b/tests/002-rpmvercmp.phpt index d83cf67..c53a183 100644 --- a/tests/002-rpmvercmp.phpt +++ b/tests/002-rpmvercmp.phpt @@ -29,11 +29,53 @@ $ok = true; foreach ($cases as $case) { list($a,$b,$expected) = $case; $result = rpmvercmp($a,$b); - if ($result != $expected) { + 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 diff --git a/tests/010-rpmvercmp_error7.phpt b/tests/010-rpmvercmp_error7.phpt index c9b3875..2d5c220 100644 --- a/tests/010-rpmvercmp_error7.phpt +++ b/tests/010-rpmvercmp_error7.phpt @@ -10,16 +10,20 @@ if (PHP_VERSION_ID >= 80000) print "skip only for PHP 7"; var_dump(rpmvercmp()); var_dump(rpmvercmp("a")); var_dump(rpmvercmp("a", "b", "c")); +var_dump(rpmvercmp("a", "b", "c", "d")); ?> Done --EXPECTF-- -Warning: rpmvercmp() expects exactly 2 parameters, 0 given in %s +Warning: rpmvercmp() expects at least 2 parameters, 0 given in %s NULL -Warning: rpmvercmp() expects exactly 2 parameters, 1 given in %s +Warning: rpmvercmp() expects at least 2 parameters, 1 given in %s NULL -Warning: rpmvercmp() expects exactly 2 parameters, 3 given in %s +Warning: rpmvercmp(): c is not a valid comparison operator in %s +NULL + +Warning: rpmvercmp() expects at most 3 parameters, 4 given in %s NULL Done diff --git a/tests/011-rpmvercmp_error8.phpt b/tests/011-rpmvercmp_error8.phpt index 4430975..2fe6aa1 100644 --- a/tests/011-rpmvercmp_error8.phpt +++ b/tests/011-rpmvercmp_error8.phpt @@ -19,13 +19,19 @@ try { } try { var_dump(rpmvercmp("a", "b", "c")); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump(rpmvercmp("a", "b", "c", "d")); } catch (ArgumentCountError $e) { echo $e->getMessage(), "\n"; } ?> Done --EXPECTF-- -rpmvercmp() expects exactly 2 %s, 0 given -rpmvercmp() expects exactly 2 %s, 1 given -rpmvercmp() expects exactly 2 %s, 3 given +rpmvercmp() expects at least 2 %s, 0 given +rpmvercmp() expects at least 2 %s, 1 given +rpmvercmp(): Argument #3 ($operator) must be a valid comparison operator +rpmvercmp() expects at most 3 %s, 4 given Done |