@@ -10,27 +10,33 @@ fn main() {
1010#[ test]
1111fn test_documents ( ) {
1212 let mut document = DocumentTree :: new ( ) ;
13- let mut tb = TransactionBuilder :: new ( & document) ;
14- tb. insert_nodes ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
15- let transaction = tb. finalize ( ) ;
13+ let transaction = {
14+ let mut tb = TransactionBuilder :: new ( & document) ;
15+ tb. insert_nodes_at_path ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
16+ tb. finalize ( )
17+ } ;
1618 document. apply ( transaction) ;
1719
1820 assert ! ( document. node_at_path( & vec![ 0 ] . into( ) ) . is_some( ) ) ;
1921 let node = document. node_at_path ( & vec ! [ 0 ] . into ( ) ) . unwrap ( ) ;
2022 let node_data = document. arena . get ( node) . unwrap ( ) . get ( ) ;
2123 assert_eq ! ( node_data. node_type, "text" ) ;
2224
23- let mut tb = TransactionBuilder :: new ( & document) ;
24- tb. update_attributes (
25- & vec ! [ 0 ] . into ( ) ,
26- HashMap :: from ( [ ( "subtype" . into ( ) , Some ( "bullet-list" . into ( ) ) ) ] ) ,
27- ) ;
28- let transaction = tb. finalize ( ) ;
25+ let transaction = {
26+ let mut tb = TransactionBuilder :: new ( & document) ;
27+ tb. update_attributes_at_path (
28+ & vec ! [ 0 ] . into ( ) ,
29+ HashMap :: from ( [ ( "subtype" . into ( ) , Some ( "bullet-list" . into ( ) ) ) ] ) ,
30+ ) ;
31+ tb. finalize ( )
32+ } ;
2933 document. apply ( transaction) ;
3034
31- let mut tb = TransactionBuilder :: new ( & document) ;
32- tb. delete_node ( & vec ! [ 0 ] . into ( ) ) ;
33- let transaction = tb. finalize ( ) ;
35+ let transaction = {
36+ let mut tb = TransactionBuilder :: new ( & document) ;
37+ tb. delete_node_at_path ( & vec ! [ 0 ] . into ( ) ) ;
38+ tb. finalize ( )
39+ } ;
3440 document. apply ( transaction) ;
3541 assert ! ( document. node_at_path( & vec![ 0 ] . into( ) ) . is_none( ) ) ;
3642}
@@ -40,16 +46,16 @@ fn test_inserts_nodes() {
4046 let mut document = DocumentTree :: new ( ) ;
4147 let transaction = {
4248 let mut tb = TransactionBuilder :: new ( & document) ;
43- tb. insert_nodes ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
44- tb. insert_nodes ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
45- tb. insert_nodes ( & vec ! [ 2 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
49+ tb. insert_nodes_at_path ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
50+ tb. insert_nodes_at_path ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
51+ tb. insert_nodes_at_path ( & vec ! [ 2 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
4652 tb. finalize ( )
4753 } ;
4854 document. apply ( transaction) ;
4955
5056 let transaction = {
5157 let mut tb = TransactionBuilder :: new ( & document) ;
52- tb. insert_nodes ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
58+ tb. insert_nodes_at_path ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
5359 tb. finalize ( )
5460 } ;
5561 document. apply ( transaction) ;
@@ -60,18 +66,16 @@ fn test_update_nodes() {
6066 let mut document = DocumentTree :: new ( ) ;
6167 let transaction = {
6268 let mut tb = TransactionBuilder :: new ( & document) ;
63- tb. insert_nodes ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
64- tb. insert_nodes ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
65- tb. insert_nodes ( & vec ! [ 2 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
69+ tb. insert_nodes_at_path ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
70+ tb. insert_nodes_at_path ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
71+ tb. insert_nodes_at_path ( & vec ! [ 2 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
6672 tb. finalize ( )
6773 } ;
6874 document. apply ( transaction) ;
6975
7076 let transaction = {
7177 let mut tb = TransactionBuilder :: new ( & document) ;
72- tb. update_attributes ( & vec ! [ 1 ] . into ( ) , HashMap :: from ( [
73- ( "bolded" . into ( ) , Some ( "true" . into ( ) ) ) ,
74- ] ) ) ;
78+ tb. update_attributes_at_path ( & vec ! [ 1 ] . into ( ) , HashMap :: from ( [ ( "bolded" . into ( ) , Some ( "true" . into ( ) ) ) ] ) ) ;
7579 tb. finalize ( )
7680 } ;
7781 document. apply ( transaction) ;
@@ -81,3 +85,26 @@ fn test_update_nodes() {
8185 let is_bold = node_data. attributes . borrow ( ) . 0 . get ( "bolded" ) . unwrap ( ) . clone ( ) ;
8286 assert_eq ! ( is_bold. unwrap( ) , "true" ) ;
8387}
88+
89+ #[ test]
90+ fn test_delete_nodes ( ) {
91+ let mut document = DocumentTree :: new ( ) ;
92+ let transaction = {
93+ let mut tb = TransactionBuilder :: new ( & document) ;
94+ tb. insert_nodes_at_path ( & vec ! [ 0 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
95+ tb. insert_nodes_at_path ( & vec ! [ 1 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
96+ tb. insert_nodes_at_path ( & vec ! [ 2 ] . into ( ) , & vec ! [ NodeData :: new( "text" ) ] ) ;
97+ tb. finalize ( )
98+ } ;
99+ document. apply ( transaction) ;
100+
101+ let transaction = {
102+ let mut tb = TransactionBuilder :: new ( & document) ;
103+ tb. delete_node_at_path ( & Position ( vec ! [ 1 ] ) ) ;
104+ tb. finalize ( )
105+ } ;
106+ document. apply ( transaction) ;
107+
108+ let len = document. root . children ( & document. arena ) . fold ( 0 , |count, _| count + 1 ) ;
109+ assert_eq ! ( len, 2 ) ;
110+ }
0 commit comments