50 lines
1.4 KiB
Haskell
50 lines
1.4 KiB
Haskell
module Gyehoek.Test.Sexp.Print where
|
|
|
|
import Test.Tasty (TestTree, testGroup, TestName)
|
|
import Test.Tasty.HUnit
|
|
import Gyehoek.Prelude
|
|
import Gyehoek.Sexp.Syntax qualified as S
|
|
import Gyehoek.Sexp.Print qualified as Sut
|
|
import System.FilePath ((</>))
|
|
import Test.Tasty.Silver
|
|
|
|
|
|
tcase = tcaseW 80
|
|
|
|
tcaseW :: Int -> TestName -> S.Datum -> TestTree
|
|
tcaseW width name ast =
|
|
goldenVsAction
|
|
name
|
|
("golden/print" </> name)
|
|
(pure $ Sut.printDatumW width ast)
|
|
id
|
|
|
|
thinWide name x = testGroup name
|
|
[ tcase (name <> "-wide") x
|
|
, tcaseW 4 (name <> "-thin") x
|
|
]
|
|
|
|
datumBegin xs = S.indentWith (S.NSpecial 0) . S.List $
|
|
(S.adorn S.SynBuiltin . S.Symbol $ "begin") : xs
|
|
|
|
datumLambda formals body =
|
|
S.indentWith (S.NSpecial 1) . S.List $
|
|
(S.adorn S.SynBuiltin . S.Symbol $ "lambda") : formals : body
|
|
|
|
test_print = testGroup "sexp pretty printer" $
|
|
[ tcase "null" $ S.List []
|
|
, thinWide "simple-list" $
|
|
S.List [ S.Symbol s | s <- ["가","나","다","라"] ]
|
|
, thinWide "begin-nonempty" $
|
|
S.indentWith (S.NSpecial 0) $
|
|
datumBegin [ S.Symbol "책을"
|
|
, S.Symbol "더"
|
|
, S.Symbol "먹으세요~!"
|
|
]
|
|
, thinWide "lambda" $
|
|
datumLambda (S.List [S.Symbol "어간", S.Symbol "어미"])
|
|
[ S.List [S.Symbol "display", S.Symbol "꾸깃"] ]
|
|
, tcase "rainbow" $
|
|
S.List [S.List [S.List [S.List [S.List []]]]]
|
|
]
|