Skip to content

Commit

Permalink
Add Cobuf encode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dopamane committed Aug 13, 2024
1 parent 430072d commit e7855a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Bayeux/Buffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module Bayeux.Buffer
( MonadBuffer(..)
, Cobuf(..)
, Fsm(..)
) where

import Bayeux.Cell hiding (le)
Expand Down
2 changes: 1 addition & 1 deletion lib/Bayeux/Uart.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Bayeux.Uart
, spramReverse
) where

import Bayeux.Buffer hiding (Cobuf(..))
import Bayeux.Buffer hiding (Cobuf(..), Fsm(..))
import Bayeux.Cell
import Bayeux.Encode
import Bayeux.Ice40.Spram
Expand Down
19 changes: 19 additions & 0 deletions test/Test/Bayeux/Buffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ module Test.Bayeux.Buffer
) where

import Bayeux.Buffer
import Bayeux.Encode
import Bayeux.Width
import Data.Array
import Data.Finite
import Data.Word
import Test.Tasty
import Test.Tasty.HUnit
import Yosys.Rtl

tests :: [TestTree]
tests =
Expand All @@ -17,4 +21,19 @@ tests =
, testCase "CobufByte" $ width (undefined :: Cobuf 4 Word8) @?= 36
, testCase "CobufBig" $ width (undefined :: Cobuf 99 (Maybe Word32)) @?= 3276
]
, testGroup "encode"
[ let actual = Cobuf Idle 0 Nothing {-(listArray (0 :: Finite 1, 0) [False])-} :: Cobuf 1 Bool
in testCase "CobufNothing" $ encode actual @?= [B0, B0, B0, B0]

, let actual = Cobuf Busy 2 $ Just $ listArray (0 :: Finite 4, 3) [0xAB :: Word8, 0xBC, 0xCD, 0xEF]
in testCase "CobufJust" $ encode actual @?=
[ B1 -- fsm
, B1, B0 -- ix
, B1 -- Maybe
, B1, B0, B1, B0, B1, B0, B1, B1 -- 0xAB
, B1, B0, B1, B1, B1, B1, B0, B0 -- 0xBC
, B1, B1, B0, B0, B1, B1, B0, B1 -- 0xCD
, B1, B1, B1, B0, B1, B1, B1, B1 -- 0xEF
]
]
]

0 comments on commit e7855a6

Please sign in to comment.