quox/tests/PrettyExtra.idr

46 lines
1.3 KiB
Idris
Raw Normal View History

2023-03-25 15:55:28 -04:00
module PrettyExtra
import public Quox.Pretty
import public Quox.Name
import TAP
export
squash : String -> String
squash = pack . squash' . unpack . trim where
squash' : List Char -> List Char
squash' [] = []
squash' (c :: cs) =
2023-05-14 13:58:46 -04:00
if isSpace c then ' ' :: squash' (dropWhile isSpace cs)
else c :: squash' cs
public export
Printer : Type -> Type
Printer a = {opts : _} -> a -> Eff Pretty (Doc opts)
export
renderSquash : ({opts : _} -> Doc opts) -> String
renderSquash doc = squash $ render (Opts 10000) doc
2023-03-25 15:55:28 -04:00
export
2023-05-14 13:58:46 -04:00
prettySquash : Printer a -> Flavor -> a -> String
prettySquash pr f x =
renderSquash $ runPrettyWith Outer f noHighlight 0 (pr x)
2023-03-25 15:55:28 -04:00
export
2023-05-14 13:58:46 -04:00
testPretty : Printer a -> a -> (uni, asc : String) ->
2023-03-25 15:55:28 -04:00
{default uni label : String} -> Test
2023-05-14 13:58:46 -04:00
testPretty pr t uni asc {label} = test {e = Info} label $ do
2023-03-25 15:55:28 -04:00
let uni = squash uni; asc = squash asc
2023-05-14 13:58:46 -04:00
uni' = prettySquash pr Unicode t
asc' = prettySquash pr Ascii t
2023-03-25 15:55:28 -04:00
unless (uni == uni') $ Left [("exp", uni), ("got", uni')]
unless (asc == asc') $ Left [("exp", asc), ("got", asc')]
2023-05-14 13:58:46 -04:00
export
runPrettyDef : Eff Pretty a -> a
runPrettyDef = runPrettyWith Outer Unicode noHighlight 0
export
prettyStr : ({opts : _} -> Eff Pretty (Doc opts)) -> String
prettyStr doc = render (Opts 60) $ runPrettyDef doc