Skip to content

Commit

Permalink
Add tests for SShow
Browse files Browse the repository at this point in the history
  • Loading branch information
krame505 committed Oct 18, 2024
1 parent cf346f0 commit 373f86c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions testsuite/bsc.lib/SShow/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for "make clean" to work everywhere

CONFDIR = $(realpath ../..)

include $(CONFDIR)/clean.mk
6 changes: 6 additions & 0 deletions testsuite/bsc.lib/SShow/SShow.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# tests for elaboration-time classic-syntax show library

compile_verilog_pass TestSShow.bs sysTestSShow

compare_file sysTestSShow.out
47 changes: 47 additions & 0 deletions testsuite/bsc.lib/SShow/TestSShow.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package TestSShow where

import SShow
import ListN
import Vector
import BuildVector
import BuildList

data Foo = A (UInt 8) Bool Bar
| B (Int 16)
| C
| D {a :: (Bit 8); b :: Foo}
deriving (FShow)

struct Bar =
foo :: Foo
x :: (UInt 8)
deriving (FShow)

data Baz a = Baz a a
deriving (FShow)

struct Qux =
x :: a -> a -- Higher rank
y :: Int 8

sysTestSShow :: Module Empty
sysTestSShow = module
out <- openFile "sysTestSShow.out" WriteMode

hPutStrLn out (sshow (42 :: UInt 8))
hPutStrLn out (sshow (321 :: Integer))
hPutStrLn out (sshow (3.14 :: Real))
hPutStrLn out (sshow '*')
hPutStrLn out (sshow "Hello")
hPutStrLn out (sshow ())
hPutStrLn out (sshow (Bar {x=42; foo=C}))
hPutStrLn out (sshow (A 12 True (Bar {foo=D {a=34; b=C}; x=42})))
hPutStrLn out (sshow (Baz C (A 12 True (Bar {foo=D {a=34; b=C}; x=42}))))
hPutStrLn out (sshow ((vec (Bar {x=42; foo=C}) (Bar {x=3; foo=B 2323})) :: Vector 2 Bar))
hPutStrLn out (sshow $ vectorToArray ((vec (Bar {x=42; foo=C}) (Bar {x=3; foo=B 2323})) :: Vector 2 Bar))
hPutStrLn out (sshow ((lst (Bar {x=42; foo=C}) (Bar {x=3; foo=B 2323})) :: List Bar))
hPutStrLn out (sshow ((Bar {x=42; foo=C}) :> (Bar {x=3; foo=B 2323}) :> ListN.nil))
hPutStrLn out (sshow ("x", ((Left 123) :: Either (UInt 8) Bar, False)))
hPutStrLn out (sshow $ Qux {x = id; y = 42;})

hClose out
15 changes: 15 additions & 0 deletions testsuite/bsc.lib/SShow/sysTestSShow.out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
42
321
3.14
'*'
"Hello"
()
Bar {foo=C; x=42}
A 12 True (Bar {foo=D {a=34; b=C}; x=42})
Baz C (A 12 True (Bar {foo=D {a=34; b=C}; x=42}))
[Bar {foo=C; x=42}, Bar {foo=B 2323; x=3}]
[Bar {foo=C; x=42}, Bar {foo=B 2323; x=3}]
[Bar {foo=C; x=42}, Bar {foo=B 2323; x=3}]
[Bar {foo=C; x=42}, Bar {foo=B 2323; x=3}]
("x", Left 123, False)
Qux {x=<polymorphic value>; y=42}

0 comments on commit 373f86c

Please sign in to comment.