@@ -73,15 +73,15 @@ fn operation_update_node_body_deserialize_test() {
7373}
7474
7575#[ test]
76- fn operation_insert_transform_test ( ) {
76+ fn operation_insert_op_transform_test ( ) {
7777 let node_1 = NodeDataBuilder :: new ( "text_1" ) . build ( ) ;
7878 let node_2 = NodeDataBuilder :: new ( "text_2" ) . build ( ) ;
7979 let op_1 = NodeOperation :: Insert {
8080 path : Path ( vec ! [ 0 , 1 ] ) ,
8181 nodes : vec ! [ node_1] ,
8282 } ;
8383
84- let mut insert_2 = NodeOperation :: Insert {
84+ let insert_2 = NodeOperation :: Insert {
8585 path : Path ( vec ! [ 0 , 1 ] ) ,
8686 nodes : vec ! [ node_2] ,
8787 } ;
@@ -95,14 +95,23 @@ fn operation_insert_transform_test() {
9595}
9696
9797#[ test]
98- fn operation_insert_transform_test2 ( ) {
98+ fn operation_insert_transform_test ( ) {
9999 let mut test = NodeTest :: new ( ) ;
100100 let node_data_1 = NodeDataBuilder :: new ( "text_1" ) . build ( ) ;
101101 let node_data_2 = NodeDataBuilder :: new ( "text_2" ) . build ( ) ;
102- let node_2: Node = node_data_2. clone ( ) . into ( ) ;
103102 let node_data_3 = NodeDataBuilder :: new ( "text_3" ) . build ( ) ;
104103 let node_3: Node = node_data_3. clone ( ) . into ( ) ;
105-
104+ //
105+ // rev_id:1 0: text_1
106+ // rev_id:2 1: text_2
107+ //
108+ // Insert a new operation with rev_id 1.But the rev_id:1 is already exist, so
109+ // it needs to do the transform.
110+ //
111+ // --> 1:text_3
112+ // transform into:
113+ // --> 2:text_3
114+ //
106115 let scripts = vec ! [
107116 InsertNode {
108117 path: 0 . into( ) ,
@@ -119,14 +128,65 @@ fn operation_insert_transform_test2() {
119128 node_data: node_data_3. clone( ) ,
120129 rev_id: 1 ,
121130 } ,
122- // AssertNode {
123- // path: 2.into(),
124- // expected: node_2,
125- // },
126131 AssertNode {
132+ path: 2 . into( ) ,
133+ expected: Some ( node_3) ,
134+ } ,
135+ ] ;
136+ test. run_scripts ( scripts) ;
137+ }
138+
139+ #[ test]
140+ fn operation_delete_transform_test ( ) {
141+ let mut test = NodeTest :: new ( ) ;
142+ let node_data_1 = NodeDataBuilder :: new ( "text_1" ) . build ( ) ;
143+ let node_data_2 = NodeDataBuilder :: new ( "text_2" ) . build ( ) ;
144+ let node_data_3 = NodeDataBuilder :: new ( "text_3" ) . build ( ) ;
145+ let node_3: Node = node_data_3. clone ( ) . into ( ) ;
146+
147+ let scripts = vec ! [
148+ InsertNode {
149+ path: 0 . into( ) ,
150+ node_data: node_data_1. clone( ) ,
151+ rev_id: 1 ,
152+ } ,
153+ InsertNode {
127154 path: 1 . into( ) ,
128- expected: node_3,
155+ node_data: node_data_2. clone( ) ,
156+ rev_id: 2 ,
157+ } ,
158+ // The node's in the tree will be:
159+ // 0: text_1
160+ // 2: text_2
161+ //
162+ // The insert action is happened concurrently with the delete action, because they
163+ // share the same rev_id. aka, 3. The delete action is want to delete the node at index 1,
164+ // but it was moved to index 2.
165+ InsertNode {
166+ path: 1 . into( ) ,
167+ node_data: node_data_3. clone( ) ,
168+ rev_id: 3 ,
169+ } ,
170+ //
171+ // 0: text_1
172+ // 1: text_3
173+ // 2: text_2
174+ //
175+ // The path of the delete action will be transformed to a new path that point to the text_2.
176+ // 1 -> 2
177+ DeleteNode {
178+ path: 1 . into( ) ,
179+ rev_id: 3 ,
180+ } ,
181+ AssertNode {
182+ path: 1 . into( ) ,
183+ expected: Some ( node_3) ,
184+ } ,
185+ AssertNode {
186+ path: 2 . into( ) ,
187+ expected: None ,
129188 } ,
189+ AssertNumberOfNodesAtPath { path: None , len: 2 } ,
130190 ] ;
131191 test. run_scripts ( scripts) ;
132192}
0 commit comments