Skip to content

Commit c89b9a8

Browse files
authored
Merge pull request #491 from tlaplus/feature/fix-deleted-value-handling
Correct deleted value handling
2 parents 795b867 + 8bd98bb commit c89b9a8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/model/check.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class Value {
167167
}
168168

169169
setDeleted(): Value {
170-
this.changeType = Change.MODIFIED;
170+
this.changeType = Change.DELETED;
171171
return this;
172172
}
173173

@@ -237,6 +237,13 @@ export abstract class CollectionValue extends Value {
237237
}
238238
}
239239
}
240+
if (this.deletedItems) {
241+
for (const item of this.deletedItems) {
242+
if (item.id === id) {
243+
return item;
244+
}
245+
}
246+
}
240247
return undefined;
241248
}
242249

tests/suite/model/check.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ suite('Check Model Test Suite', () => {
160160
);
161161
});
162162

163+
test('Marks deleted values as deleted', () => {
164+
const value = v(1, 'one').setDeleted();
165+
assert.equal(value.changeType, Change.DELETED);
166+
});
167+
163168
test('Finds subitem by ID', () => {
164169
Value.switchIdsOn();
165170
const varOne = v(1, 'one');
@@ -187,6 +192,21 @@ suite('Check Model Test Suite', () => {
187192
const found = root.findItem(varOne.id);
188193
assert.equal(typeof found, 'undefined');
189194
});
195+
196+
test('Finds deleted items from deletedItems list', () => {
197+
Value.switchIdsOn();
198+
const seqValue = seq('foo', v(1, 'one'));
199+
seqValue.addDeletedItems([v(2, 'two')]);
200+
const root = struct(ROOT,
201+
v('bar', 'BAR'),
202+
seqValue);
203+
const deleted = seqValue.deletedItems ? seqValue.deletedItems[0] : undefined;
204+
assert.ok(deleted);
205+
const found = root.findItem(deleted!.id);
206+
assert.ok(found);
207+
assert.equal(found?.id, deleted!.id);
208+
assert.equal(found?.changeType, Change.DELETED);
209+
});
190210
});
191211

192212
function assertChanges(prev: CollectionValue, state: CollectionValue, expect: CollectionValue) {

0 commit comments

Comments
 (0)