File: Unit.hs

package info (click to toggle)
haskell-primitive-unaligned 0.1.1.2-7
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 100 kB
  • sloc: haskell: 382; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# language BangPatterns #-}
{-# language ScopedTypeVariables #-}

import Control.Monad (when)
import Data.Word
import Data.Primitive.ByteArray
import Data.Primitive.ByteArray.Unaligned

main :: IO ()
main = do
  putStrLn "Start"
  putStrLn "A"
  testA
  putStrLn "Finished"

testA :: IO ()
testA = do
  let expected = 0x0123456789ABCDEF :: Word64
  marr <- newByteArray 16
  setByteArray marr 0 16 (0x00 :: Word8)
  writeUnalignedByteArray marr 3 expected
  actualX :: Word64 <- readUnalignedByteArray marr 3
  when (expected /= actualX) $ fail "testA"
  arr <- unsafeFreezeByteArray marr
  let actualY = indexUnalignedByteArray arr 3
  when (expected /= actualY) $ fail "testA"