PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/quick/allbranches.php

http://github.com/facebook/hiphop-php
PHP | 114 lines | 97 code | 10 blank | 7 comment | 21 complexity | f790fc5a3f81b260e5aa5831a6a1b0fb 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. trait T {
  3. public function binary($la, $ra) {
  4. // Stick this in a trait, so we get different copies for different
  5. // data.
  6. for ($i = 0; $i < 3; $i++) {
  7. // Compare each to each. Do so a couple times, so we exercise both
  8. // directions of each branch through multiple executions. (The jit
  9. // uses different code for the first several executions of any given
  10. // branch.)
  11. foreach ($la as $l) foreach ($ra as $r) {
  12. if ($l === $r) echo "$l === $r\n";
  13. if ($l !== $r) echo "$l !== $r\n";
  14. if ($l == $r) echo "$l == $r\n";
  15. if ($l != $r) echo "$l != $r\n";
  16. if ($l <= $r) echo "$l <= $r\n";
  17. if ($l >= $r) echo "$l >= $r\n";
  18. if ($l < $r) echo "$l < $r\n";
  19. if ($l > $r) echo "$l > $r\n";
  20. }
  21. }
  22. }
  23. public function unary($la) {
  24. for ($i = 0; $i < 3; $i++) {
  25. foreach($la as $l) {
  26. if (is_int($l)) echo "$l is_int\n";
  27. if (is_string($l)) echo "$l is_string\n";
  28. if (is_double($l)) echo "$l is_double\n";
  29. if (is_null($l)) echo "$l is_null\n";
  30. if (is_double($l)) echo "$l is_double\n";
  31. if (is_array($l)) echo "$l is_array\n";
  32. if (is_object($l)) echo "$l is_object\n";
  33. }
  34. }
  35. }
  36. }
  37. function banner($s) {
  38. printf("---- %40s\n", $s);
  39. }
  40. class Ascending {
  41. use T;
  42. function __construct() {
  43. banner("asc");
  44. $this->binary(varray[-1, 0, 1], varray[-1, 0, 1]);
  45. }
  46. }
  47. class Descending {
  48. use T;
  49. function __construct() {
  50. banner("desc");
  51. $this->binary(varray[1, 0, -1], varray[1, 0, -1]);
  52. }
  53. }
  54. class Equal {
  55. use T;
  56. function __construct() {
  57. banner("eq");
  58. $this->binary(varray[0, 0, 0], varray[0, 0, 0]);
  59. }
  60. }
  61. class Str {
  62. use T;
  63. function __construct() {
  64. $a = varray["a", "abc", "abcd", "0", "1", "2"];
  65. $this->binary($a, $a);
  66. }
  67. }
  68. class NotEqual {
  69. use T;
  70. function __construct() {
  71. banner("neq");
  72. $this->binary(varray[1, 2, 3], varray[4, 5, 6]);
  73. }
  74. }
  75. class Bools {
  76. use T;
  77. function __construct() {
  78. banner("bools");
  79. $this->binary(varray[false, true], varray[false, true]);
  80. }
  81. }
  82. class C {
  83. public function __toString() { return "snee!"; }
  84. }
  85. class DifferentTypes {
  86. use T;
  87. function __construct() {
  88. banner("weirdTypes");
  89. $a = varray[0, true, null, 0.3, "str", varray[], new C()];
  90. $this->unary($a);
  91. }
  92. }
  93. <<__EntryPoint>>
  94. function main() {
  95. // disable array -> "Array" conversion notice
  96. error_reporting(error_reporting() & ~E_NOTICE);
  97. $asc = new Ascending();
  98. $desc = new Descending();
  99. $eq = new Equal();
  100. $str = new Str();
  101. $neq = new NotEqual();
  102. $bools = new Bools();
  103. $diff = new DifferentTypes();
  104. }