xgo/runtime/vm_bitwise_test.go

37 lines
1 KiB
Go
Raw Normal View History

2019-01-11 13:27:28 +03:00
package runtime_test
2019-01-09 10:17:42 +03:00
import "testing"
func TestBitwise(t *testing.T) {
expect(t, `out = 1 & 1`, nil, 1)
expect(t, `out = 1 & 0`, nil, 0)
expect(t, `out = 0 & 1`, nil, 0)
expect(t, `out = 0 & 0`, nil, 0)
expect(t, `out = 1 | 1`, nil, 1)
expect(t, `out = 1 | 0`, nil, 1)
expect(t, `out = 0 | 1`, nil, 1)
expect(t, `out = 0 | 0`, nil, 0)
expect(t, `out = 1 ^ 1`, nil, 0)
expect(t, `out = 1 ^ 0`, nil, 1)
expect(t, `out = 0 ^ 1`, nil, 1)
expect(t, `out = 0 ^ 0`, nil, 0)
expect(t, `out = 1 &^ 1`, nil, 0)
expect(t, `out = 1 &^ 0`, nil, 1)
expect(t, `out = 0 &^ 1`, nil, 0)
expect(t, `out = 0 &^ 0`, nil, 0)
expect(t, `out = 1 << 2`, nil, 4)
expect(t, `out = 16 >> 2`, nil, 4)
2019-01-09 10:17:42 +03:00
expect(t, `out = 1; out &= 1`, nil, 1)
expect(t, `out = 1; out |= 0`, nil, 1)
expect(t, `out = 1; out ^= 0`, nil, 1)
expect(t, `out = 1; out &^= 0`, nil, 1)
expect(t, `out = 1; out <<= 2`, nil, 4)
expect(t, `out = 16; out >>= 2`, nil, 4)
2019-01-09 10:17:42 +03:00
expect(t, `out = ^0`, nil, ^0)
expect(t, `out = ^1`, nil, ^1)
expect(t, `out = ^55`, nil, ^55)
expect(t, `out = ^-55`, nil, ^-55)
2019-01-09 10:17:42 +03:00
}