Add string operator enlist-input[] (#4948)

* Add string operator titlelist[]

* Update strings.js

* Update strings.js

* Add tests
optimising-macrocalls
saqimtiaz 2020-11-01 18:11:46 +01:00 zatwierdzone przez GitHub
rodzic a6efc14a7c
commit e7245a709c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 11 dodań i 4 usunięć

Wyświetl plik

@ -56,14 +56,14 @@ exports.trim = function(source,operator,options) {
return result;
};
// makeStringBinaryOperator(
// function(a) {return [$tw.utils.trim(a)];}
// );
exports.split = makeStringBinaryOperator(
function(a,b) {return ("" + a).split(b);}
);
exports["enlist-input"] = makeStringBinaryOperator(
function(a) {return $tw.utils.parseStringArray("" + a);}
);
exports.join = makeStringReducingOperator(
function(accumulator,value,operand) {
if(accumulator === null) {

Wyświetl plik

@ -160,6 +160,13 @@ function runTests(wiki) {
expect(wiki.filterTiddlers("[enlist[one two three]addsuffix[!]]").join(",")).toBe("one!,two!,three!");
});
it("should handle the enlist-input operator", function() {
expect(wiki.filterTiddlers("[[one two three]enlist-input[]]").join(",")).toBe("one,two,three");
expect(wiki.filterTiddlers("[[one two three]] [[four five six]] +[enlist-input[]]").join(",")).toBe("one,two,three,four,five,six");
expect(wiki.filterTiddlers("[[one two three]] [[four five six]] [[seven eight]] +[enlist-input[]]").join(",")).toBe("one,two,three,four,five,six,seven,eight");
expect(wiki.filterTiddlers("[[]] +[enlist-input[]]").join(",")).toBe("");
});
it("should handle the then and else operators", function() {
expect(wiki.filterTiddlers("[modifier[JoeBloggs]then[Susi]]").join(",")).toBe("Susi");
expect(wiki.filterTiddlers("[!modifier[JoeBloggs]then[Susi]]").join(",")).toBe("Susi,Susi,Susi,Susi,Susi,Susi,Susi,Susi");