1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 00:50:28 +00:00

Fix issue with linked list remove (#7065)

* Added failing linked-list test for #7059

* Fixed linked-list remove bug #7059
This commit is contained in:
btheado 2022-11-26 09:05:10 -06:00 committed by GitHub
parent 32a033bb50
commit bea1a6b14f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -136,13 +136,9 @@ function _removeOne(list,value) {
// we need to know if the FIRST value is the last in the list, not the last.
if(next !== undefined) {
if(typeof list.prev[next] === "object") {
if(prev === undefined) {
// Must have been first, and 'i' would be 0.
list.prev[next].shift();
} else {
var i = list.prev[next].indexOf(value);
list.prev[next][i] = prev;
}
// Nothing special needed for first since list.prev[next][0] will be 'undefined'
var i = list.prev[next].indexOf(value);
list.prev[next][i] = prev;
} else {
list.prev[next] = prev;
}

View File

@ -137,6 +137,21 @@ describe("LinkedList class tests", function() {
compare(pushTop(newPair(["C", "X", "A", "A"]), "X")); // CAAX
});
it("can remove all instances of a multi-instance value #7059", function() {
// Remove duplicate items when one or more items between the duplicates
// are not removed and the first of those duplicates is not the first item.
// These tests used to fail prior to the fix to #7059
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "C", "A", "A"])); // B
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["C", "A", "A", "A"])); // B
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "A", "A"])); // CB
compare(remove(newPair(["A", "A", "C", "B", "A"]), ["A", "A", "A", "C"])); // B
compare(remove(newPair(["A", "A", "B", "A"]), ["A", "A", "A"])); // B
compare(remove(newPair(["A", "A", "B", "A"]), ["A", "A", "A", "B"])); //
compare(remove(newPair(["C", "A", "B", "A"]), ["C", "A", "A"])); // B
compare(remove(newPair(["C", "A", "B", "A", "C"]), ["C", "A", "A", "C"])); // B
compare(remove(newPair(["B", "A", "B", "A"]), ["B", "A", "A"])); // B
});
it("can handle particularly nasty pushTop pitfall", function() {
var pair = newPair(["A", "B", "A", "C"]);
pushTop(pair, "A"); // BACA