aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/v/tests/supports__likely__test.v
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/vlib/v/tests/supports__likely__test.v')
-rw-r--r--v_windows/v/vlib/v/tests/supports__likely__test.v32
1 files changed, 32 insertions, 0 deletions
diff --git a/v_windows/v/vlib/v/tests/supports__likely__test.v b/v_windows/v/vlib/v/tests/supports__likely__test.v
new file mode 100644
index 0000000..ec7e50b
--- /dev/null
+++ b/v_windows/v/vlib/v/tests/supports__likely__test.v
@@ -0,0 +1,32 @@
+// _likely_(expr) should be compilable, and it should return the expr
+fn test_likely_type() {
+ assert typeof(_likely_(false)).name == 'bool'
+ assert _likely_(false) == false
+ assert _likely_(true) == true
+}
+
+fn test_likely() {
+ if _likely_(2 < 10) {
+ assert true
+ eprintln('ok, happens every time')
+ } else {
+ eprintln('happens *infrequently*')
+ assert false
+ }
+}
+
+fn test_likely_returns_the_value_of_its_bool_argument() {
+ i := 123
+ if _likely_(i < 2) {
+ assert false
+ } else {
+ assert true
+ }
+}
+
+// _unlikely_ is the same as _likely_ from the V point of view:
+fn test_unlikely_type() {
+ assert typeof(_unlikely_(false)).name == 'bool'
+ assert _unlikely_(false) == false
+ assert _unlikely_(true) == true
+}