mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-27 01:14:44 +00:00
fixed helper function and added tests
tests: ok
This commit is contained in:
parent
a88ead9c0f
commit
f684a6beb0
@ -4,8 +4,8 @@ rem test TiddlyWiki5 for tiddlywiki.com
|
||||
|
||||
rem Run the test edition to run the node.js tests and to generate test.html for tests in the browser
|
||||
|
||||
node .\tiddlywiki.js ^
|
||||
.\editions\test ^
|
||||
node ..\tiddlywiki.js ^
|
||||
..\editions\test ^
|
||||
--verbose ^
|
||||
--rendertiddler $:/core/save/all test.html text/plain ^
|
||||
|| exit 1
|
||||
|
@ -20,16 +20,16 @@ exports.each = function(source,operator,options) {
|
||||
var results = [],
|
||||
values = {},
|
||||
field = operator.operand || "title",
|
||||
add = function(v) {
|
||||
if(!$tw.utils.hop(values,v)) {
|
||||
values[v] = true;
|
||||
results.push(v);
|
||||
add = function(val,title) {
|
||||
if(!$tw.utils.hop(values,val)) {
|
||||
values[val] = true;
|
||||
results.push(title);
|
||||
}
|
||||
};
|
||||
if("list" !== operator.suffix) {
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler) {
|
||||
add("title" === field ? title : tiddler.getFieldString(operator.operand));
|
||||
add("title" === field ? title : tiddler.getFieldString(field),title);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@ -38,7 +38,7 @@ exports.each = function(source,operator,options) {
|
||||
$tw.utils.each(
|
||||
options.wiki.getTiddlerList(title,field),
|
||||
function(value) {
|
||||
add(value);
|
||||
add(value,value);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -51,12 +51,14 @@ describe("Filter tests", function() {
|
||||
title: "TiddlerOne",
|
||||
text: "The quick brown fox in $:/TiddlerTwo",
|
||||
tags: ["one"],
|
||||
authors: "Joe Bloggs",
|
||||
modifier: "JoeBloggs",
|
||||
modified: "201304152222"});
|
||||
wiki.addTiddler({
|
||||
title: "$:/TiddlerTwo",
|
||||
text: "The rain in Spain\nfalls mainly on the plain and [[a fourth tiddler]]",
|
||||
tags: ["two"],
|
||||
authors: "[[John Doe]]",
|
||||
modifier: "JohnDoe",
|
||||
modified: "201304152211"});
|
||||
wiki.addTiddler({
|
||||
@ -217,6 +219,8 @@ describe("Filter tests", function() {
|
||||
|
||||
it("should handle the each operator", function() {
|
||||
expect(wiki.filterTiddlers("[each[modifier]sort[title]]").join(",")).toBe("$:/TiddlerTwo,TiddlerOne");
|
||||
expect(wiki.filterTiddlers("[each:list[tags]sort[title]]").join(",")).toBe("one,two");
|
||||
expect(wiki.filterTiddlers("[each:list[authors]sort[title]]").join(",")).toBe("Bloggs,Joe,John Doe");
|
||||
});
|
||||
|
||||
it("should handle the eachday operator", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user