From 0c63f5c80db4aa7c76eaa69701fb52032c48193b Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 14 Apr 2020 20:38:11 +0300 Subject: [PATCH] builtin: test left/right shift precedence --- vlib/builtin/array_test.v | 13 +++++++++++++ vlib/builtin/int_test.v | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 8d66af686a..94091e163d 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -692,6 +692,19 @@ fn test_hex(){ assert st1.hex() == "41".repeat(100) } +fn test_left_shift_precendence() { + mut arr := []int + arr << 1 + 1 + arr << 1 - 1 + arr << 2 / 1 + arr << 2 * 1 + + assert arr[0] == 2 + assert arr[1] == 0 + assert arr[2] == 2 + assert arr[3] == 2 +} + fn test_array_with_cap() { a := []int{cap:10, len:1 } //assert a.len == 1 diff --git a/vlib/builtin/int_test.v b/vlib/builtin/int_test.v index 296605fbd3..9927cc198d 100644 --- a/vlib/builtin/int_test.v +++ b/vlib/builtin/int_test.v @@ -100,6 +100,16 @@ fn test_xor_precendence() { assert (1 ^ 0 > 1) == ((1 ^ 0) > 1) } +fn test_left_shift_precendence() { + assert (2 << 4 | 3) == ((2 << 4) | 3) + assert (2 << 4 | 3) != (2 << (4 | 3)) +} + +fn test_right_shift_precendence() { + assert (256 >> 4 | 3) == ((256 >> 4) | 3) + assert (256 >> 4 | 3) != (256 >> (4 | 3)) +} + fn test_i8_print() { b := i8(0) println(b)