More sorting tests to help with #6053

sort-optimisations
jeremy@jermolene.com 2021-09-20 11:04:37 +01:00
rodzic ef2aeac7de
commit 0be39cfbc2
1 zmienionych plików z 871 dodań i 860 usunięć

Wyświetl plik

@ -8,13 +8,13 @@ Tests the filtering mechanism.
\*/
(function(){
/* jslint node: true, browser: true */
/* eslint-env node, browser, jasmine */
/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
/* global $tw, require */
"use strict";
/* jslint node: true, browser: true */
/* eslint-env node, browser, jasmine */
/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
/* global $tw, require */
"use strict";
describe("Filter tests", function() {
describe("Filter tests", function() {
// Test filter parsing
it("should parse new-style rich operator suffixes", function() {
@ -73,7 +73,7 @@ describe("Filter tests", function() {
runTests(wiki);
});
function setupWiki(wikiOptions) {
function setupWiki(wikiOptions) {
// Create a wiki
var wiki = new $tw.Wiki(wikiOptions);
// Add a plugin containing some shadow tiddlers
@ -173,10 +173,10 @@ function setupWiki(wikiOptions) {
wiki.unpackPluginTiddlers();
wiki.addIndexersToWiki();
return wiki;
}
}
// Our tests
function runTests(wiki) {
// Our tests
function runTests(wiki) {
it("should handle the enlist operator", function() {
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() {
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[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
// 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");
});
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() {
expect(wiki.filterTiddlers("[sort[title]first[]]").join(",")).toBe("$:/ShadowPlugin");
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");
});
/* listops filters */
/* listops filters */
it("should handle the allafter operator", function() {
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() {
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() {
@ -880,8 +890,9 @@ function runTests(wiki) {
);
});
}
}
});
});
})();
})();