2024-09-09 08:16:02 +00:00
|
|
|
use loro_internal::{LoroDoc, TreeParentId};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tree_index() {
|
|
|
|
let doc = LoroDoc::new_auto_commit();
|
|
|
|
doc.set_peer_id(0).unwrap();
|
|
|
|
let tree = doc.get_tree("tree");
|
|
|
|
let root = tree.create(TreeParentId::Root).unwrap();
|
|
|
|
let child = tree.create(root.into()).unwrap();
|
|
|
|
let child2 = tree.create_at(root.into(), 0).unwrap();
|
|
|
|
// sort with OpID
|
2024-11-18 06:32:56 +00:00
|
|
|
assert_eq!(tree.get_index_by_tree_id(&child).unwrap(), 1);
|
|
|
|
assert_eq!(tree.get_index_by_tree_id(&child2).unwrap(), 0);
|
2024-09-09 08:16:02 +00:00
|
|
|
|
|
|
|
let doc = LoroDoc::new_auto_commit();
|
|
|
|
doc.set_peer_id(0).unwrap();
|
|
|
|
let tree = doc.get_tree("tree");
|
2024-09-11 03:16:31 +00:00
|
|
|
tree.enable_fractional_index(0);
|
2024-09-09 08:16:02 +00:00
|
|
|
let root = tree.create(TreeParentId::Root).unwrap();
|
|
|
|
let child = tree.create(root.into()).unwrap();
|
|
|
|
let child2 = tree.create_at(root.into(), 0).unwrap();
|
|
|
|
// sort with fractional index
|
|
|
|
assert_eq!(tree.get_index_by_tree_id(&child).unwrap(), 1);
|
|
|
|
assert_eq!(tree.get_index_by_tree_id(&child2).unwrap(), 0);
|
|
|
|
}
|