v2 / vlib / v / tests / supports__likely__test.v
32 lines · 29 sloc · 713 bytes · cbefe6c32f7784cbf54794b4c676bd278cced75c
Raw
1// _likely_(expr) should be compilable, and it should return the expr
2fn test_likely_type() {
3 assert typeof(_likely_(false)).name == 'bool'
4 assert _likely_(false) == false
5 assert _likely_(true) == true
6}
7
8fn 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
18fn 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:
28fn test_unlikely_type() {
29 assert typeof(_unlikely_(false)).name == 'bool'
30 assert _unlikely_(false) == false
31 assert _unlikely_(true) == true
32}
33