Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty print readable unicode characters #2041

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/swarm-lang/Swarm/Language/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

------------------------------------------------------------
Expand Down Expand Up @@ -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 -> "<a" <> pretty r <> ">"
Expand Down
1 change: 1 addition & 0 deletions swarm.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ library swarm-lang
terminal-size >=0.3 && <1.0,
text,
text-rope >=0.2 && <0.3,
unicode-show >=0.1 && <0.2,
vector,
vty,
witch,
Expand Down
4 changes: 4 additions & 0 deletions test/unit/TestEval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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
Expand Down