Debian Codegraph @

test/bit.fnl

raw
1 (local t (require :test.faith))
2 (local fennel (require :fennel))
3
4 (macro == [form expected]
5 `(let [(ok# val#) (pcall fennel.eval ,(view form)
6 {:useBitLib (not= nil _G.bit)})]
7 (t.is ok# val#)
8 (t.= ,expected val#)))
9
10 (fn test-shifts []
11 (== (lshift 33 2) 132)
12 (== (lshift 1) 2)
13 (== (rshift 33 2) 8)
14 (let [(ok? msg) (pcall fennel.compileString "(lshift)")]
15 (t.is (not ok?))
16 (t.match "Expected more than 0 arguments" msg)))
17
18 (fn test-ops []
19 ;; multiple args
20 (== (band 0x16 0xd) 0x4)
21 (== (band 0xff 0x91) 0x91)
22 (== (bor 0x1 0x2 0x4 0x8) 0xf)
23 (== (bxor 0x2 0xf0) 0xf2)
24 ;; one arg
25 (== (bxor 1) 1)
26 (== (bor 0x33) 0x33)
27 (== (band 0x93) 0x93)
28 (== (bnot 26) -27)
29 ;; no args
30 (== (band) -1)
31 (== (bor) 0)
32 (== (bxor) 0))
33
34 ;; skip the test on PUC 5.1 and 5.2
35 (if (or (rawget _G :jit) (not (_VERSION:find "5%.[12]")))
36 {: test-shifts
37 : test-ops}
38 {})