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

Fix lastChild and read insert tests #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Yoga/Tree/Zipper.purs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ last l@(Loc r) = case uncons (reverse r.after) of
Loc
$
{ node: c
, before: cs <> r.before
, before: cs <> r.node : r.before
, after: []
, parents: r.parents
}
Expand Down
88 changes: 71 additions & 17 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Test.Spec (describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.Reporter (consoleReporter)
import Test.Spec.Runner (runSpec)
import Yoga.Tree (Tree, leaf, scanTree, showTree)
import Yoga.Tree.Zipper (down, findDownWhere, findFromRoot, findUp, flattenLocDepthFirst, fromTree, modifyValue, next, toTree, value)
import Yoga.Tree (Tree, leaf, mkLeaf, scanTree, showTree)
import Yoga.Tree.Zipper (down, findDownWhere, findFromRoot, findUp, firstChild, flattenLocDepthFirst, fromTree, insertAfter, lastChild, modifyValue, next, toTree, value)

newtype SpecTree a = SpecTree (Tree a)

Expand Down Expand Up @@ -106,21 +106,75 @@ main = launchAff_ $ runSpec [ consoleReporter ] do
SpecTree root' `shouldEqual` SpecTree result
SpecTree root'' `shouldEqual` SpecTree result'

-- it "Insert" do

-- let root1 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ down root)
-- let root2 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (down root) >>= next >>= next >>= down >>= next >>= down)
-- let root3 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (firstChild root))
-- let root4 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (lastChild root))

-- let result1 = 1 :< []
-- let result2 = 1 :< []
-- let result3 = 1 :< []
-- let result4 = 1 :< []
-- shouldEqual (eq root1 result1) true
-- shouldEqual (eq root2 result2) true
-- shouldEqual (eq root3 result3) true
-- shouldEqual (eq root4 result4) true
it "Insert" do

let root1 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ down root)
let root2 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (down root) >>= next >>= next >>= down >>= next >>= down)
let root3 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (firstChild root))
let root4 = unsafePartial $ toTree $ insertAfter (mkLeaf 100) (fromJust $ (lastChild root))

let result1 =
1 :<
[ (2 :< [])
, (100 :< [])
, (3 :< [])
, (4 :<
[ (5 :< [])
, (6 :<
[7 :< []])
, (8 :< [])
]
)
]

let result2 =
1 :<
[ (2 :< [])
, (3 :< [])
, (4 :<
[ (5 :< [])
, (6 :<
[ (7 :< [])
, (100 :< [])
])
, (8 :< [])
]
)
]
let result3 =
1 :<
[ (2 :< [])
, (100 :< [])
, (3 :< [])
, (4 :<
[ (5 :< [])
, (6 :<
[(7 :< [])
]
)
, (8 :< [])
]
)
]
let result4 =
1 :<
[ (2 :< [])
, (3 :< [])
, (4 :<
[ (5 :< [])
, (6 :<
[ 7 :< [] ])
, (8 :< [])
]
)
, (100 :< [])
]


shouldEqual (eq root1 result1) true
shouldEqual (eq root2 result2) true
shouldEqual (eq root3 result3) true
shouldEqual (eq root4 result4) true

it "Should findDownWhere with single node" do
let tree = 1 :< []
Expand Down