1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-24 22:33:16 +00:00

fixed helper function and added tests

tests: ok
This commit is contained in:
Tobias Beer 2015-01-27 02:02:15 +01:00
parent a88ead9c0f
commit f684a6beb0
3 changed files with 12 additions and 8 deletions

View File

@ -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 rem Run the test edition to run the node.js tests and to generate test.html for tests in the browser
node .\tiddlywiki.js ^ node ..\tiddlywiki.js ^
.\editions\test ^ ..\editions\test ^
--verbose ^ --verbose ^
--rendertiddler $:/core/save/all test.html text/plain ^ --rendertiddler $:/core/save/all test.html text/plain ^
|| exit 1 || exit 1

View File

@ -20,16 +20,16 @@ exports.each = function(source,operator,options) {
var results = [], var results = [],
values = {}, values = {},
field = operator.operand || "title", field = operator.operand || "title",
add = function(v) { add = function(val,title) {
if(!$tw.utils.hop(values,v)) { if(!$tw.utils.hop(values,val)) {
values[v] = true; values[val] = true;
results.push(v); results.push(title);
} }
}; };
if("list" !== operator.suffix) { if("list" !== operator.suffix) {
source(function(tiddler,title) { source(function(tiddler,title) {
if(tiddler) { if(tiddler) {
add("title" === field ? title : tiddler.getFieldString(operator.operand)); add("title" === field ? title : tiddler.getFieldString(field),title);
} }
}); });
} else { } else {
@ -38,7 +38,7 @@ exports.each = function(source,operator,options) {
$tw.utils.each( $tw.utils.each(
options.wiki.getTiddlerList(title,field), options.wiki.getTiddlerList(title,field),
function(value) { function(value) {
add(value); add(value,value);
} }
); );
} }

View File

@ -51,12 +51,14 @@ describe("Filter tests", function() {
title: "TiddlerOne", title: "TiddlerOne",
text: "The quick brown fox in $:/TiddlerTwo", text: "The quick brown fox in $:/TiddlerTwo",
tags: ["one"], tags: ["one"],
authors: "Joe Bloggs",
modifier: "JoeBloggs", modifier: "JoeBloggs",
modified: "201304152222"}); modified: "201304152222"});
wiki.addTiddler({ wiki.addTiddler({
title: "$:/TiddlerTwo", title: "$:/TiddlerTwo",
text: "The rain in Spain\nfalls mainly on the plain and [[a fourth tiddler]]", text: "The rain in Spain\nfalls mainly on the plain and [[a fourth tiddler]]",
tags: ["two"], tags: ["two"],
authors: "[[John Doe]]",
modifier: "JohnDoe", modifier: "JohnDoe",
modified: "201304152211"}); modified: "201304152211"});
wiki.addTiddler({ wiki.addTiddler({
@ -217,6 +219,8 @@ describe("Filter tests", function() {
it("should handle the each operator", function() { it("should handle the each operator", function() {
expect(wiki.filterTiddlers("[each[modifier]sort[title]]").join(",")).toBe("$:/TiddlerTwo,TiddlerOne"); 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() { it("should handle the eachday operator", function() {