@@ -230,6 +230,27 @@ genTests = (type) ->
230230 assert .deepEqual [{p : [100 ], si : ' hi' }], type .compose [{p : [100 ], si : ' h' }], [{p : [101 ], si : ' i' }]
231231 assert .deepEqual [{p : [], t : ' text0' , o : [{p : 100 , i : ' hi' }]}], type .compose [{p : [], t : ' text0' , o : [{p : 100 , i : ' h' }]}], [{p : [], t : ' text0' , o : [{p : 101 , i : ' i' }]}]
232232
233+ describe ' #invertWithDoc()' , ->
234+ it ' passes the doc to the subtype' , ->
235+ op = null
236+ doc = null
237+
238+ type .registerSubtype
239+ name : ' invertible'
240+ invertWithDoc : (o , d ) ->
241+ op = o
242+ doc = d
243+
244+ type .invertWithDoc [{p : [' foo' , ' bar' ], t : ' invertible' , o : [{increment : 1 }]}], {foo : {bar : 5 }}
245+ assert .deepEqual [{increment : 1 }], op
246+ assert .deepEqual 5 , doc
247+
248+ it ' throws if the subtype does not support inversion' , ->
249+ type .registerSubtype
250+ name : ' not-invertible'
251+
252+ assert .throws -> type .invertWithDoc [{p : [' foo' ], t : ' not-invertible' , o : [{increment : 1 }]}], {foo : 5 }
253+
233254 it ' moves ops on a moved element with the element' , ->
234255 assert .deepEqual [{p : [10 ], ld : ' x' }], type .transform [{p : [4 ], ld : ' x' }], [{p : [4 ], lm : 10 }], ' left'
235256 assert .deepEqual [{p : [10 , 1 ], si : ' a' }], type .transform [{p : [4 , 1 ], si : ' a' }], [{p : [4 ], lm : 10 }], ' left'
0 commit comments