1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Joining an empty list should return an empty list (#4853)

This commit is contained in:
Robin Munn 2020-09-25 00:37:51 +07:00 committed by GitHub
parent 72c07a3f81
commit d5cf4112fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -90,6 +90,9 @@ function makeStringReducingOperator(fnCalc,initialValue) {
source(function(tiddler,title) {
result.push(title);
});
if(result.length === 0) {
return [];
}
return [result.reduce(function(accumulator,currentValue) {
return fnCalc(accumulator,currentValue,operator.operand || "");
},initialValue) || ""];

View File

@ -463,7 +463,7 @@ function runTests(wiki) {
expect(wiki.filterTiddlers("John Paul George Ringo +[split[e]]").join(",")).toBe("John,Paul,G,org,,Ringo");
expect(wiki.filterTiddlers("John Paul George Ringo +[join[ ]split[e]join[ee]split[ ]]").join(",")).toBe("John,Paul,Geeorgee,Ringo");
// Ensure that join doesn't return null if passed empty list
expect(wiki.filterTiddlers("Test +[butlast[]join[ ]]")).toEqual([""]);
expect(wiki.filterTiddlers("Test +[butlast[]join[ ]]")).toEqual([]);
// Ensure that join correctly handles empty strings in source
expect(wiki.filterTiddlers("[[]] Paul +[join[-]]").join(",")).toBe("-Paul");
expect(wiki.filterTiddlers("[[ John ]] [[Paul ]] [[ George]] Ringo +[trim[]join[-]]").join(",")).toBe("John-Paul-George-Ringo");