Permalink
Browse files

Fix rendering bug with parentheses.

  • Loading branch information...
leepike committed May 17, 2012
1 parent d139942 commit 10f0d9697a2ce7f41da679286a437e095cf8eb0e
Showing with 14 additions and 3 deletions.
  1. +0 −1 TODO.md
  2. +14 −2 src/Test/SmartCheck/Render.hs
View
@@ -26,7 +26,6 @@ TODO
* Make SubT from Forest into Tree(?) More natural and allows to index the head.
-* Fix parentheses bug for showing Strings.
Won't Do / Can't Do
-----------------------------------------------
@@ -6,6 +6,7 @@ module Test.SmartCheck.Render
import Test.SmartCheck.Types
import Test.SmartCheck.DataToTree
+import Data.Maybe
import Data.Tree
import Data.Data
import Data.List
@@ -56,15 +57,26 @@ replaceWithVars format d idxs vars =
---------------------------------------------------------------------------------
--- | Make a string out a Tree of Strings. Put parentheses around subterms.
+-- | Make a string out a Tree of Strings. Put parentheses around complex
+-- subterms, where "complex" means we have two or more items (i.e., there's a
+-- space).
stitchTree :: Tree String -> String
stitchTree = stitch
where
stitch (Node str forest) = str ++ " " ++ (unwords $ map stitchTree' forest)
- stitchTree' (Node str []) = str
+ stitchTree' (Node str []) = if isJust $ find isSpace str
+ then '(' : str ++ ")"
+ else str
stitchTree' node = '(' : stitch node ++ ")"
+ -- stitchTree' (Node str rst) | find isSpace str =
+ -- stitch (Node '(' : stitch str ++ ")" )'(' : stitch str ++ ")"
+ -- | otherwise = stitch node
+
+ -- stitchTree' (Node str []) = str
+ -- stitchTree' node = '(' : stitch node ++ ")"
+
---------------------------------------------------------------------------------
-- Make a Tree out of a Data value. On each level, we just use the user-defined

0 comments on commit 10f0d96

Please sign in to comment.