/hphp/test/zend/good/ext/standard/tests/versioning/version_compare.php
PHP | 49 lines | 48 code | 1 blank | 0 comment | 1 complexity | 08056e95f5788ee553181183d28155d2 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?hh
- function test($v1, $v2) {
- $compare = version_compare($v1, $v2);
- switch ($compare) {
- case -1:
- print "$v1 < $v2\n";
- break;
- case 1:
- print "$v1 > $v2\n";
- break;
- case 0:
- default:
- print "$v1 = $v2\n";
- break;
- }
- }
- <<__EntryPoint>> function main(): void {
- print "TESTING COMPARE\n";
- $special_forms = varray["-dev", "a1", "b1", "RC1", "rc1", "", "pl1"];
- $operators = varray[
- "lt", "<",
- "le", "<=",
- "gt", ">",
- "ge", ">=",
- "eq", "=", "==",
- "ne", "<>", "!="
- ];
- test("1", "2");
- test("10", "2");
- test("1.0", "1.1");
- test("1.2", "1.0.1");
- foreach ($special_forms as $f1) {
- foreach ($special_forms as $f2) {
- test("1.0$f1", "1.0$f2");
- }
- }
- print "TESTING OPERATORS\n";
- foreach ($special_forms as $f1) {
- foreach ($special_forms as $f2) {
- foreach ($operators as $op) {
- $v1 = "1.0$f1";
- $v2 = "1.0$f2";
- $test = version_compare($v1, $v2, $op) ? "true" : "false";
- printf("%7s %2s %-7s : %s\n", $v1, $op, $v2, $test);
- }
- }
- }
- }