Skip to content

Instantly share code, notes, and snippets.

@rnewman
Created February 4, 2016 03:18
Show Gist options
  • Save rnewman/9cf59439b0fccc6f60be to your computer and use it in GitHub Desktop.
Save rnewman/9cf59439b0fccc6f60be to your computer and use it in GitHub Desktop.
Tests that pass!
// This test describes a scenario like this:
//
// [] [] []
// [M] [T] [M] [T] [M] [T]
// | | | | | |
// [C] [A] [C] [A] [C] [A]
// | | | |
// [D] [D] [B] [B]
// | |
// F E
//
// That is: we have locally added 'E' to folder B and deleted folder D,
// and remotely added 'F' to folder D and deleted folder B.
//
// This is a fundamental conflict that would ordinarily produce orphans.
// Our resolution for this is to put those orphans _somewhere_.
//
// That place is the lowest surviving parent: walk the tree until we find
// a folder that still exists, and put the orphans there. This is a little
// better than just dumping the records into Unsorted Bookmarks, and no
// more complex than dumping them into the closest root.
//
// We expect:
//
// []
// [M] [T]
// | |
// [C] [A]
// | |
// F E
//
// This test describes a scenario like this:
//
// [] [] []
// [X] [Y] [X] [Y] [X] [Y]
// | | | |
// [A] C [A] [A]
// / \ / \ / | \
// B E B C B D C
//
// That is: we have locally added 'D' to folder A, and remotely moved
// A to a different root, added 'E', and moved 'C' back to the old root.
//
// Our expected result is:
//
// []
// [X] [Y]
// | |
// [A] C
// / | \
// B D E
//
// … but we'll settle for any order of children for [A] that preserves B < E
// and B < D -- in other words, (B E D) and (B D E) are both acceptable.
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment