| 1 | // _likely_(expr) should be compilable, and it should return the expr |
| 2 | fn test_likely_type() { |
| 3 | assert typeof(_likely_(false)).name == 'bool' |
| 4 | assert _likely_(false) == false |
| 5 | assert _likely_(true) == true |
| 6 | } |
| 7 | |
| 8 | fn test_likely() { |
| 9 | if _likely_(2 < 10) { |
| 10 | assert true |
| 11 | eprintln('ok, happens every time') |
| 12 | } else { |
| 13 | eprintln('happens *infrequently*') |
| 14 | assert false |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fn test_likely_returns_the_value_of_its_bool_argument() { |
| 19 | i := 123 |
| 20 | if _likely_(i < 2) { |
| 21 | assert false |
| 22 | } else { |
| 23 | assert true |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // _unlikely_ is the same as _likely_ from the V point of view: |
| 28 | fn test_unlikely_type() { |
| 29 | assert typeof(_unlikely_(false)).name == 'bool' |
| 30 | assert _unlikely_(false) == false |
| 31 | assert _unlikely_(true) == true |
| 32 | } |
| 33 | |