1
- import org.modelix.model.api.ConceptReference
2
- import org.modelix.model.api.ITree
3
- import org.modelix.model.api.NodeReference
4
- import org.modelix.model.lazy.CLTree
5
- import org.modelix.model.lazy.ObjectStoreCache
6
- import org.modelix.model.persistent.MapBaseStore
7
- import kotlin.test.Test
8
- import kotlin.test.assertEquals
9
-
10
1
/*
11
2
* Copyright (c) 2023.
12
3
*
@@ -23,6 +14,16 @@ import kotlin.test.assertEquals
23
14
* limitations under the License.
24
15
*/
25
16
17
+ import org.modelix.model.api.ConceptReference
18
+ import org.modelix.model.api.ITree
19
+ import org.modelix.model.api.NodeReference
20
+ import org.modelix.model.lazy.CLTree
21
+ import org.modelix.model.lazy.ObjectStoreCache
22
+ import org.modelix.model.persistent.MapBaseStore
23
+ import kotlin.test.Test
24
+ import kotlin.test.assertEquals
25
+ import kotlin.test.fail
26
+
26
27
class DiffTest {
27
28
28
29
@Test
@@ -70,6 +71,43 @@ class DiffTest {
70
71
}
71
72
}
72
73
74
+ @Test
75
+ fun moveChildOutsideNode () {
76
+ runTest(
77
+ setOf (
78
+ TreeChangeCollector .ChildrenChangedEvent (ITree .ROOT_ID , " children1" ),
79
+ TreeChangeCollector .ChildrenChangedEvent (200 , " children1" ),
80
+ TreeChangeCollector .ContainmentChangedEvent (100 ),
81
+ ),
82
+ {
83
+ it.addNewChild(ITree .ROOT_ID , " children1" , - 1 , 100 , null as ConceptReference ? )
84
+ .addNewChild(ITree .ROOT_ID , " children2" , - 1 , 200 , null as ConceptReference ? )
85
+ },
86
+ {
87
+ it.moveChild(200 , " children1" , - 1 , 100 )
88
+ },
89
+ )
90
+ }
91
+
92
+ @Test
93
+ fun moveChildInsideNode () {
94
+ runTest(
95
+ setOf (
96
+ TreeChangeCollector .ChildrenChangedEvent (ITree .ROOT_ID , " children1" ),
97
+ TreeChangeCollector .ChildrenChangedEvent (ITree .ROOT_ID , " children2" ),
98
+ TreeChangeCollector .ContainmentChangedEvent (100 ),
99
+ ),
100
+ {
101
+ it
102
+ .addNewChild(ITree .ROOT_ID , " children1" , - 1 , 100 , null as ConceptReference ? )
103
+ .addNewChild(ITree .ROOT_ID , " children1" , - 1 , 101 , null as ConceptReference ? )
104
+ },
105
+ {
106
+ it.moveChild(ITree .ROOT_ID , " children2" , - 1 , 100 )
107
+ },
108
+ )
109
+ }
110
+
73
111
@Test
74
112
fun removeChild () {
75
113
runTest(
@@ -90,11 +128,19 @@ class DiffTest {
90
128
runTest(expectedEvents, { it }, mutator)
91
129
}
92
130
93
- private fun runTest (expectedEvents : Set <TreeChangeCollector .ChangeEvent >, initialMutator : (ITree ) -> ITree , mutator : (ITree ) -> ITree ) {
131
+ private fun runTest (
132
+ expectedEvents : Set <TreeChangeCollector .ChangeEvent >,
133
+ initialMutator : (ITree ) -> ITree ,
134
+ mutator : (ITree ) -> ITree ,
135
+ ) {
94
136
val tree1 = initialMutator(CLTree .builder(ObjectStoreCache (MapBaseStore ())).build())
95
137
val tree2 = mutator(tree1)
96
138
val collector = TreeChangeCollector ()
97
139
tree2.visitChanges(tree1, collector)
140
+ val duplicateEvents = collector.events.groupBy { it }.filter { it.value.size > 1 }.map { it.key }
141
+ if (duplicateEvents.isNotEmpty()) {
142
+ fail(" duplicate events: $duplicateEvents " )
143
+ }
98
144
99
145
assertEquals(
100
146
expectedEvents,
0 commit comments