loro/crates/loro-internal/tests/tree.rs
Zixuan Chen d6966aca34
fix: fractional index is enabled by default now (#561)
* fix: tree should use jitter 0 by default

Otherwise, there may be inconsistency between the event and the actual data. But this will increase the cost when the index property is not used.

* chore: add changeset

* chore: fix warning

* refactor: enable tree move by default

* docs: update related docs
2024-11-18 14:32:56 +08:00

25 lines
977 B
Rust

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
assert_eq!(tree.get_index_by_tree_id(&child).unwrap(), 1);
assert_eq!(tree.get_index_by_tree_id(&child2).unwrap(), 0);
let doc = LoroDoc::new_auto_commit();
doc.set_peer_id(0).unwrap();
let tree = doc.get_tree("tree");
tree.enable_fractional_index(0);
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);
}