kopia lustrzana https://github.com/miklobit/TiddlyWiki5
More sorting tests to help with #6053
rodzic
ef2aeac7de
commit
0be39cfbc2
|
@ -8,13 +8,13 @@ Tests the filtering mechanism.
|
||||||
\*/
|
\*/
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
/* jslint node: true, browser: true */
|
/* jslint node: true, browser: true */
|
||||||
/* eslint-env node, browser, jasmine */
|
/* eslint-env node, browser, jasmine */
|
||||||
/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
|
/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
|
||||||
/* global $tw, require */
|
/* global $tw, require */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("Filter tests", function() {
|
describe("Filter tests", function() {
|
||||||
|
|
||||||
// Test filter parsing
|
// Test filter parsing
|
||||||
it("should parse new-style rich operator suffixes", function() {
|
it("should parse new-style rich operator suffixes", function() {
|
||||||
|
@ -73,7 +73,7 @@ describe("Filter tests", function() {
|
||||||
runTests(wiki);
|
runTests(wiki);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupWiki(wikiOptions) {
|
function setupWiki(wikiOptions) {
|
||||||
// Create a wiki
|
// Create a wiki
|
||||||
var wiki = new $tw.Wiki(wikiOptions);
|
var wiki = new $tw.Wiki(wikiOptions);
|
||||||
// Add a plugin containing some shadow tiddlers
|
// Add a plugin containing some shadow tiddlers
|
||||||
|
@ -173,10 +173,10 @@ function setupWiki(wikiOptions) {
|
||||||
wiki.unpackPluginTiddlers();
|
wiki.unpackPluginTiddlers();
|
||||||
wiki.addIndexersToWiki();
|
wiki.addIndexersToWiki();
|
||||||
return wiki;
|
return wiki;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our tests
|
// Our tests
|
||||||
function runTests(wiki) {
|
function runTests(wiki) {
|
||||||
|
|
||||||
it("should handle the enlist operator", function() {
|
it("should handle the enlist operator", function() {
|
||||||
expect(wiki.filterTiddlers("[enlist[one two three]addsuffix[!]]").join(",")).toBe("one!,two!,three!");
|
expect(wiki.filterTiddlers("[enlist[one two three]addsuffix[!]]").join(",")).toBe("one!,two!,three!");
|
||||||
|
@ -265,11 +265,20 @@ function runTests(wiki) {
|
||||||
it("should handle the sort and sortcs operators", function() {
|
it("should handle the sort and sortcs operators", function() {
|
||||||
expect(wiki.filterTiddlers("[sort[title]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne");
|
expect(wiki.filterTiddlers("[sort[title]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne");
|
||||||
expect(wiki.filterTiddlers("[!sort[title]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
expect(wiki.filterTiddlers("[!sort[title]]").join(",")).toBe("TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin");
|
||||||
|
expect(wiki.filterTiddlers("[sort[modified]]").join(",")).toBe("$:/ShadowPlugin,a fourth tiddler,one,hasList,has filter,filter regexp test,$:/TiddlerTwo,TiddlerOne,Tiddler Three");
|
||||||
|
expect(wiki.filterTiddlers("[!sort[modified]]").join(",")).toBe("Tiddler Three,TiddlerOne,$:/TiddlerTwo,$:/ShadowPlugin,a fourth tiddler,one,hasList,has filter,filter regexp test");
|
||||||
// Temporarily commenting out the following two lines because of platform differences for localeCompare between the browser and Node.js
|
// Temporarily commenting out the following two lines because of platform differences for localeCompare between the browser and Node.js
|
||||||
// expect(wiki.filterTiddlers("[sortcs[title]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three,TiddlerOne,a fourth tiddler,one");
|
// expect(wiki.filterTiddlers("[sortcs[title]]").join(",")).toBe("$:/TiddlerTwo,Tiddler Three,TiddlerOne,a fourth tiddler,one");
|
||||||
// expect(wiki.filterTiddlers("[!sortcs[title]]").join(",")).toBe("one,a fourth tiddler,TiddlerOne,Tiddler Three,$:/TiddlerTwo");
|
// expect(wiki.filterTiddlers("[!sortcs[title]]").join(",")).toBe("one,a fourth tiddler,TiddlerOne,Tiddler Three,$:/TiddlerTwo");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle the nsort and nsortcs operators", function() {
|
||||||
|
expect(wiki.filterTiddlers("3 2 0 1 5 Apple add Beta beatle +[nsort[]]").join(",")).toBe("0,1,2,3,5,add,Apple,beatle,Beta");
|
||||||
|
expect(wiki.filterTiddlers("3 2 0 1 5 Apple add Beta beatle +[!nsort[]]").join(",")).toBe("Beta,beatle,Apple,add,5,3,2,1,0");
|
||||||
|
expect(wiki.filterTiddlers("3 2 0 1 5 Apple add Beta beatle +[nsortcs[]]").join(",")).toBe("0,1,2,3,5,add,Apple,beatle,Beta");
|
||||||
|
expect(wiki.filterTiddlers("3 2 0 1 5 Apple add Beta beatle +[!nsortcs[]]").join(",")).toBe("Beta,beatle,Apple,add,5,3,2,1,0");
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle the reverse, first, last, butfirst, butlast, rest and nth operators", function() {
|
it("should handle the reverse, first, last, butfirst, butlast, rest and nth operators", function() {
|
||||||
expect(wiki.filterTiddlers("[sort[title]first[]]").join(",")).toBe("$:/ShadowPlugin");
|
expect(wiki.filterTiddlers("[sort[title]first[]]").join(",")).toBe("$:/ShadowPlugin");
|
||||||
expect(wiki.filterTiddlers("[sort[title]first[2]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo");
|
expect(wiki.filterTiddlers("[sort[title]first[2]]").join(",")).toBe("$:/ShadowPlugin,$:/TiddlerTwo");
|
||||||
|
@ -546,7 +555,7 @@ function runTests(wiki) {
|
||||||
expect(wiki.filterTiddlers("1 2 3 4 +[min[2]]").join(",")).toBe("1,2,2,2");
|
expect(wiki.filterTiddlers("1 2 3 4 +[min[2]]").join(",")).toBe("1,2,2,2");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* listops filters */
|
/* listops filters */
|
||||||
|
|
||||||
it("should handle the allafter operator", function() {
|
it("should handle the allafter operator", function() {
|
||||||
expect(wiki.filterTiddlers("1 2 3 4 +[allafter[]]").join(",")).toBe("");
|
expect(wiki.filterTiddlers("1 2 3 4 +[allafter[]]").join(",")).toBe("");
|
||||||
|
@ -745,6 +754,7 @@ function runTests(wiki) {
|
||||||
|
|
||||||
it("should handle the sortan operator sorting on date fields", function() {
|
it("should handle the sortan operator sorting on date fields", function() {
|
||||||
expect(wiki.filterTiddlers("TiddlerOne $:/TiddlerTwo [[Tiddler Three]] +[sortan[modified]]").join(",")).toBe("$:/TiddlerTwo,TiddlerOne,Tiddler Three");
|
expect(wiki.filterTiddlers("TiddlerOne $:/TiddlerTwo [[Tiddler Three]] +[sortan[modified]]").join(",")).toBe("$:/TiddlerTwo,TiddlerOne,Tiddler Three");
|
||||||
|
expect(wiki.filterTiddlers("hasList TiddlerOne $:/TiddlerTwo [[Tiddler Three]] +[sortan[modified]]").join(",")).toBe("hasList,$:/TiddlerTwo,TiddlerOne,Tiddler Three");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle the slugify operator", function() {
|
it("should handle the slugify operator", function() {
|
||||||
|
@ -880,8 +890,9 @@ function runTests(wiki) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
Ładowanie…
Reference in New Issue