PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/versioning/version_compare.php

http://github.com/facebook/hiphop-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
  1. <?hh
  2. function test($v1, $v2) {
  3. $compare = version_compare($v1, $v2);
  4. switch ($compare) {
  5. case -1:
  6. print "$v1 < $v2\n";
  7. break;
  8. case 1:
  9. print "$v1 > $v2\n";
  10. break;
  11. case 0:
  12. default:
  13. print "$v1 = $v2\n";
  14. break;
  15. }
  16. }
  17. <<__EntryPoint>> function main(): void {
  18. print "TESTING COMPARE\n";
  19. $special_forms = varray["-dev", "a1", "b1", "RC1", "rc1", "", "pl1"];
  20. $operators = varray[
  21. "lt", "<",
  22. "le", "<=",
  23. "gt", ">",
  24. "ge", ">=",
  25. "eq", "=", "==",
  26. "ne", "<>", "!="
  27. ];
  28. test("1", "2");
  29. test("10", "2");
  30. test("1.0", "1.1");
  31. test("1.2", "1.0.1");
  32. foreach ($special_forms as $f1) {
  33. foreach ($special_forms as $f2) {
  34. test("1.0$f1", "1.0$f2");
  35. }
  36. }
  37. print "TESTING OPERATORS\n";
  38. foreach ($special_forms as $f1) {
  39. foreach ($special_forms as $f2) {
  40. foreach ($operators as $op) {
  41. $v1 = "1.0$f1";
  42. $v2 = "1.0$f2";
  43. $test = version_compare($v1, $v2, $op) ? "true" : "false";
  44. printf("%7s %2s %-7s : %s\n", $v1, $op, $v2, $test);
  45. }
  46. }
  47. }
  48. }