Skip to content

Commit

Permalink
Merge pull request #250 from quartz55/fix/tree-zipper-moveup-reverse-…
Browse files Browse the repository at this point in the history
…leftsiblings

Reverse order of leftSiblings when moving up a TreeZipper
  • Loading branch information
andywhite37 authored Mar 16, 2020
2 parents 692c18a + 918b4f7 commit 5564a25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/Relude_TreeZipper_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,16 @@ describe("TreeZipper", () => {
expect(actual) |> toEqual(expected);
});

test("moveUpToTop maintains structure", () => {
let actual =
testTree1
|> TreeZipper.fromTree
|> TreeZipper.moveBy([`Down(2), `Right(2)])
|> Option.map(TreeZipper.moveUpToTop);
let expected = Some(testTree1 |> TreeZipper.fromTree);
expect(actual) |> toEqual(expected);
});

test("moveDown", () => {
let actual = testTree1 |> TreeZipper.fromTree |> TreeZipper.moveDown;
let expected =
Expand Down
2 changes: 1 addition & 1 deletion src/Relude_TreeZipper.re
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ let moveUp: 'a. t('a) => option(t('a)) =
rightSiblings: ancestorsHeadRight,
children:
Relude_List.flatten([
leftSiblings,
leftSiblings |> Relude_List.reverse,
[Relude_Tree.make(focus, children)],
rightSiblings,
]),
Expand Down

0 comments on commit 5564a25

Please sign in to comment.