loro/crates/loro-internal/tests/tree.rs
Leon Zhao 07671ea9fd
feat: add old parent and old index in tree diff (#452)
* feat: add old parent in tree diff

* chore: enable ci

* feat: add old_index to tree diff

* fix: new fractional index config

* fix: cargo fix

* fix: add FractionalIndexNotEnabled error

* fix: move config to tree state

* fix: error string

---------

Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-09-09 16:16:02 +08:00

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