@@ -94,6 +94,53 @@ describe("ArraySchema Tests", () => {
94
94
assert . strictEqual ( 0 , state . turns . length ) ;
95
95
} ) ;
96
96
97
+ it ( "consecutive shift calls should not break 'encodeAll'" , ( ) => {
98
+ class Entity extends Schema {
99
+ @type ( "number" ) i : number ;
100
+ }
101
+ class MyState extends Schema {
102
+ @type ( [ Entity ] ) entities ;
103
+ }
104
+
105
+ const state = new MyState ( ) ;
106
+ state . entities = [ ] ;
107
+
108
+ for ( let i = 0 ; i < 5 ; i ++ ) {
109
+ state . entities . push ( new Entity ( ) . assign ( { i } ) ) ;
110
+ }
111
+
112
+ const decodedState = createInstanceFromReflection ( state ) ;
113
+ decodedState . decode ( state . encode ( ) )
114
+
115
+ const entitiesChangeTree : ChangeTree = state . entities [ $changes ] ;
116
+ assert . deepStrictEqual ( { '0' : 0 , '1' : 1 , '2' : 2 , '3' : 3 , '4' : 4 } , entitiesChangeTree . allChanges . indexes ) ;
117
+
118
+ state . entities . shift ( ) ;
119
+ assert . deepStrictEqual ( { '0' : 1 , '1' : 2 , '2' : 3 , '3' : 4 } , entitiesChangeTree . allChanges . indexes ) ;
120
+
121
+ state . entities . shift ( ) ;
122
+ assert . deepStrictEqual ( { '0' : 2 , '1' : 3 , '2' : 4 } , entitiesChangeTree . allChanges . indexes ) ;
123
+
124
+ state . entities . shift ( ) ;
125
+ assert . deepStrictEqual ( { '0' : 3 , '1' : 4 } , entitiesChangeTree . allChanges . indexes ) ;
126
+
127
+ state . entities . shift ( ) ;
128
+ assert . deepStrictEqual ( { '0' : 4 } , entitiesChangeTree . allChanges . indexes ) ;
129
+
130
+ assertDeepStrictEqualEncodeAll ( state ) ;
131
+
132
+ decodedState . decode ( state . encode ( ) )
133
+ assertRefIdCounts ( state , decodedState ) ;
134
+
135
+ state . entities . shift ( ) ;
136
+
137
+ decodedState . decode ( state . encode ( ) )
138
+ assertRefIdCounts ( state , decodedState ) ;
139
+
140
+ // encode all
141
+ assertDeepStrictEqualEncodeAll ( state ) ;
142
+ } ) ;
143
+
97
144
it ( "mutate previous instance + shift" , ( ) => {
98
145
/**
99
146
* This test shows that flagging the `changeSet` item as `undefined`
@@ -123,14 +170,16 @@ describe("ArraySchema Tests", () => {
123
170
for ( let i = 0 ; i < 2 ; i ++ ) {
124
171
for ( let j = 0 ; j < 2 ; j ++ ) {
125
172
state . entities . forEach ( ( entity ) => entity . i ++ ) ;
126
- const entity = state . entities . shift ( ) ;
173
+ state . entities . shift ( ) ;
127
174
}
128
-
129
175
decodedState . decode ( state . encode ( ) ) ;
130
176
}
131
177
132
178
assertDeepStrictEqualEncodeAll ( state ) ;
133
179
assertRefIdCounts ( state , decodedState ) ;
180
+
181
+ state . entities . shift ( ) ;
182
+ assertDeepStrictEqualEncodeAll ( state ) ;
134
183
} ) ;
135
184
} ) ;
136
185
@@ -369,6 +418,8 @@ describe("ArraySchema Tests", () => {
369
418
console . log ( "--- 5 ---" )
370
419
371
420
assert . strictEqual ( 0 , state . turns . length ) ;
421
+
422
+ assertDeepStrictEqualEncodeAll ( state ) ;
372
423
} ) ;
373
424
} ) ;
374
425
@@ -439,6 +490,8 @@ describe("ArraySchema Tests", () => {
439
490
440
491
decodedState . decode ( state . encode ( ) ) ;
441
492
assert . deepStrictEqual ( [ 0 , 1 , 2 , 3 , 4 ] , decodedState . arrayOfNumbers . toJSON ( ) ) ;
493
+
494
+ assertDeepStrictEqualEncodeAll ( state ) ;
442
495
} ) ;
443
496
444
497
it ( "push, unshift, pop" , ( ) => {
@@ -460,6 +513,8 @@ describe("ArraySchema Tests", () => {
460
513
461
514
decodedState . decode ( state . encode ( ) ) ;
462
515
assert . deepStrictEqual ( [ 0 , 1 , 2 , 3 ] , decodedState . arrayOfNumbers . toJSON ( ) ) ;
516
+
517
+ assertDeepStrictEqualEncodeAll ( state ) ;
463
518
} ) ;
464
519
465
520
it ( "push, pop, unshift" , ( ) => {
@@ -481,6 +536,8 @@ describe("ArraySchema Tests", () => {
481
536
482
537
decodedState . decode ( state . encode ( ) ) ;
483
538
assert . deepStrictEqual ( [ 0 , 1 , 2 , 3 ] , decodedState . arrayOfNumbers . toJSON ( ) ) ;
539
+
540
+ assertDeepStrictEqualEncodeAll ( state ) ;
484
541
} ) ;
485
542
486
543
it ( "push, shift, unshift" , ( ) => {
0 commit comments