fix issue with DFO instantiation tracking of path info

This commit is contained in:
Paul Chiusano 2015-10-27 12:19:11 -04:00
parent 03caf04271
commit 415ff70898
3 changed files with 16 additions and 2 deletions

View File

@ -589,6 +589,13 @@ debugDoc (p :< l) = show p : case l of
Group r -> debugDoc r
_ -> []
leafPaths :: Path p => Doc e p -> [p]
leafPaths (p :< d) = map (Path.extend p) $ case d of
Append a b -> leafPaths a ++ leafPaths b
Nest _ r -> leafPaths r
Group r -> leafPaths r
_ -> [Path.root]
-- various instances
instance Bifunctor L where

View File

@ -368,7 +368,7 @@ view ref t = go no View.low t where
let
Symbol.Symbol _ name view = op fn
(taken, remaining) = splitAt (View.arity view) args
fmt (child,path) = (\p -> D.sub' path (go (fn ==) p child), path)
fmt (child,path) = (\p -> go (fn ==) p child, path)
applied = fromMaybe unsaturated (View.instantiate view fnP name (map fmt taken))
unsaturated = D.sub' fnP $ go no View.high fn
in

View File

@ -39,11 +39,18 @@ tests = withResource Common.node (\_ -> pure ()) $ \node -> testGroup "Term"
, testCase "hash cycles" $ assertEqual "pingpong"
(hash pingpong1)
(hash pingpong2)
, testCase "infix-rendering" $ node >>= \(_,symbol) ->
, testCase "infix-rendering (1)" $ node >>= \(_,symbol) ->
let t = num 1 `plus` num 1
in assertEqual "+"
"1 + 1"
(Doc.formatText (Width 80) (view symbol t))
, testCase "infix-rendering (2)" $ node >>= \(_,symbol) ->
do
t <- pure $ num 1 `plus` num 1
let d = view symbol t
assertEqual "path sanity check"
[Fn,Arg]
(head $ Doc.leafPaths d)
]
-- various unison terms, useful for testing