From e4c098e4a03d0a8e50fc762cf24d54254d7b1cce Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Mon, 15 Jul 2024 00:31:43 +0530 Subject: [PATCH 1/2] Pretty print readable unicode characters --- src/swarm-lang/Swarm/Language/Pretty.hs | 3 ++- swarm.cabal | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/swarm-lang/Swarm/Language/Pretty.hs b/src/swarm-lang/Swarm/Language/Pretty.hs index 04cfa0cf1..c54663484 100644 --- a/src/swarm-lang/Swarm/Language/Pretty.hs +++ b/src/swarm-lang/Swarm/Language/Pretty.hs @@ -36,6 +36,7 @@ import Swarm.Language.Syntax.Direction import Swarm.Language.Typecheck import Swarm.Language.Types import Swarm.Util (number, showEnum, showLowT, unsnocNE) +import Text.Show.Unicode (ushow) import Witch ------------------------------------------------------------ @@ -271,7 +272,7 @@ instance PrettyPrec (Term' ty) where TDir d -> ppr d TInt n -> pretty n TAntiInt v -> "$int:" <> pretty v - TText s -> fromString (show s) + TText s -> fromString (ushow s) TAntiText v -> "$str:" <> pretty v TBool b -> bool "false" "true" b TRobot r -> " pretty r <> ">" diff --git a/swarm.cabal b/swarm.cabal index ffc098a67..fc64f2591 100644 --- a/swarm.cabal +++ b/swarm.cabal @@ -191,6 +191,7 @@ library swarm-lang terminal-size >=0.3 && <1.0, text, text-rope >=0.2 && <0.3, + unicode-show, vector, vty, witch, From 7aed1394ccd9c1ddb54c25cf43db15c8237e53f8 Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Mon, 15 Jul 2024 09:59:09 +0530 Subject: [PATCH 2/2] bounds + unit tests --- swarm.cabal | 2 +- test/unit/TestEval.hs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/swarm.cabal b/swarm.cabal index fc64f2591..15ee9ba62 100644 --- a/swarm.cabal +++ b/swarm.cabal @@ -191,7 +191,7 @@ library swarm-lang terminal-size >=0.3 && <1.0, text, text-rope >=0.2 && <0.3, - unicode-show, + unicode-show >=0.1 && <0.2, vector, vty, witch, diff --git a/test/unit/TestEval.hs b/test/unit/TestEval.hs index 09f6affac..37cc7ee61 100644 --- a/test/unit/TestEval.hs +++ b/test/unit/TestEval.hs @@ -227,6 +227,9 @@ testEval g = , testCase "format function" ("format (\\x. x + 1)" `evaluatesTo` VText "\\x. x + 1") + , testCase + "format forall" + ("format \"∀\"" `evaluatesTo` VText "\"∀\"") , testCase "concat" ("\"x = \" ++ format (2+3) ++ \"!\"" `evaluatesTo` VText "x = 5!") @@ -346,6 +349,7 @@ testEval g = where tquote :: String -> Text tquote = T.pack . show + throwsError :: Text -> (Text -> Bool) -> Assertion throwsError tm p = do result <- evaluate tm