2013-05-25 16:26:22 +00:00
/ * \
title : test - filters . js
type : application / javascript
tags : [ [ $ : / t a g s / t e s t - s p e c ] ]
Tests the filtering mechanism .
\ * /
( function ( ) {
2020-01-31 14:09:06 +00:00
/* jslint node: true, browser: true */
/* eslint-env node, browser, jasmine */
/* eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
/* global $tw, require */
2013-05-25 16:26:22 +00:00
"use strict" ;
describe ( "Filter tests" , function ( ) {
2018-10-30 17:39:18 +00:00
// Test filter parsing
it ( "should parse new-style rich operator suffixes" , function ( ) {
expect ( $tw . wiki . parseFilter ( "[search:: four, , five,, six [operand]]" ) ) . toEqual (
[ { prefix : '' , operators : [ { operator : 'search' , suffix : ': four, , five,, six ' , suffixes : [ [ ] , [ 'four' , 'five' , 'six' ] ] , operand : 'operand' } ] } ]
) ;
expect ( $tw . wiki . parseFilter ( "[search: one, two ,three :[operand]]" ) ) . toEqual (
[ { prefix : '' , operators : [ { operator : 'search' , suffix : ' one, two ,three :' , suffixes : [ [ 'one' , 'two' , 'three' ] , [ ] ] , operand : 'operand' } ] } ]
) ;
expect ( $tw . wiki . parseFilter ( "[search: one, two ,three :[operand]]" ) ) . toEqual (
[ { prefix : '' , operators : [ { operator : 'search' , suffix : ' one, two ,three :' , suffixes : [ [ 'one' , 'two' , 'three' ] , [ ] ] , operand : 'operand' } ] } ]
) ;
expect ( $tw . wiki . parseFilter ( "[search: one, two ,three : four, , five,, six [operand]]" ) ) . toEqual (
[ { prefix : '' , operators : [ { operator : 'search' , suffix : ' one, two ,three : four, , five,, six ' , suffixes : [ [ 'one' , 'two' , 'three' ] , [ 'four' , 'five' , 'six' ] ] , operand : 'operand' } ] } ]
) ;
expect ( $tw . wiki . parseFilter ( "[search: , : [operand]]" ) ) . toEqual (
2019-12-19 13:38:09 +00:00
[ { prefix : '' , operators : [ { operator : 'search' , suffix : ' , : ' , suffixes : [ [ ] , [ ] ] , operand : 'operand' } ] } ]
2018-10-30 17:39:18 +00:00
) ;
} ) ;
2019-05-24 20:07:37 +00:00
describe ( "With no indexers" , function ( ) {
var wiki = setupWiki ( { enableIndexers : [ ] } ) ;
2019-07-16 15:53:37 +00:00
it ( "should not create indexes when requested not to" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . getIndexer ( "FieldIndexer" ) ) . toBe ( null ) ;
2019-07-16 15:53:37 +00:00
} ) ;
2019-05-24 20:07:37 +00:00
runTests ( wiki ) ;
} ) ;
describe ( "With all indexers" , function ( ) {
var wiki = setupWiki ( ) ;
2019-07-16 15:53:37 +00:00
if ( wiki . getIndexer ( "FieldIndexer" ) ) {
2019-12-19 13:38:09 +00:00
wiki . getIndexer ( "FieldIndexer" ) . setMaxIndexedValueLength ( 8 ) ; // Note that JoeBloggs is 9, and John is 5
2019-07-16 15:53:37 +00:00
}
2019-05-24 20:07:37 +00:00
runTests ( wiki ) ;
} ) ;
2018-10-30 17:39:18 +00:00
2019-05-24 20:07:37 +00:00
function setupWiki ( wikiOptions ) {
2013-05-25 16:26:22 +00:00
// Create a wiki
2019-07-16 15:53:37 +00:00
var wiki = new $tw . Wiki ( wikiOptions ) ;
// Add a plugin containing some shadow tiddlers
var shadowTiddlers = {
tiddlers : {
2014-03-17 10:50:18 +00:00
"$:/TiddlerFive" : {
2019-07-16 15:53:37 +00:00
title : "$:/TiddlerFive" ,
text : "Everything in federation" ,
tags : [ "two" ]
2014-03-17 10:50:18 +00:00
} ,
"TiddlerSix" : {
2019-07-16 15:53:37 +00:00
title : "TiddlerSix" ,
text : "Missing inaction from TiddlerOne" ,
2019-12-19 13:38:09 +00:00
filter : "[[one]] [[a a]] [subfilter{hasList!!list}]" ,
2019-07-16 15:53:37 +00:00
tags : [ ]
2014-03-17 10:50:18 +00:00
} ,
"TiddlerSeventh" : {
2019-07-16 15:53:37 +00:00
title : "TiddlerSeventh" ,
text : "" ,
list : "TiddlerOne [[Tiddler Three]] [[a fourth tiddler]] MissingTiddler" ,
tags : [ "one" ]
2014-03-17 10:50:18 +00:00
} ,
"Tiddler8" : {
2019-07-16 15:53:37 +00:00
title : "Tiddler8" ,
text : "Tidd" ,
tags : [ "one" ] ,
"test-field" : "JoeBloggs"
2019-12-19 13:38:09 +00:00
}
2014-03-17 10:50:18 +00:00
}
2019-07-16 15:53:37 +00:00
} ;
wiki . addTiddler ( {
title : "$:/ShadowPlugin" ,
text : JSON . stringify ( shadowTiddlers ) ,
"plugin-type" : "plugin" ,
type : "application/json" } ) ;
2013-05-25 16:26:22 +00:00
// Add a few tiddlers
wiki . addTiddler ( {
title : "TiddlerOne" ,
text : "The quick brown fox in $:/TiddlerTwo" ,
tags : [ "one" ] ,
2020-04-25 14:22:24 +00:00
cost : "123" ,
value : "120" ,
2020-05-09 14:54:44 +00:00
slug : "tiddler-one" ,
2015-01-27 01:02:15 +00:00
authors : "Joe Bloggs" ,
2013-05-27 16:59:47 +00:00
modifier : "JoeBloggs" ,
2014-01-30 06:11:54 +00:00
modified : "201304152222" } ) ;
2013-05-25 16:26:22 +00:00
wiki . addTiddler ( {
title : "$:/TiddlerTwo" ,
text : "The rain in Spain\nfalls mainly on the plain and [[a fourth tiddler]]" ,
2013-05-27 16:59:47 +00:00
tags : [ "two" ] ,
2020-04-25 14:22:24 +00:00
cost : "42" ,
value : "190" ,
2020-05-09 14:54:44 +00:00
slug : "tiddler-two" ,
2015-01-27 01:02:15 +00:00
authors : "[[John Doe]]" ,
2019-12-19 13:38:09 +00:00
modifier : "John" ,
2014-01-30 06:11:54 +00:00
modified : "201304152211" } ) ;
2013-05-25 16:26:22 +00:00
wiki . addTiddler ( {
title : "Tiddler Three" ,
text : "The speed of sound in light\n\nThere is no TiddlerZero but TiddlerSix" ,
2013-05-27 16:59:47 +00:00
tags : [ "one" , "two" ] ,
2020-04-25 14:22:24 +00:00
cost : "56" ,
value : "80" ,
2019-12-19 13:38:09 +00:00
modifier : "John" ,
2014-01-30 14:28:54 +00:00
modified : "201304162202" } ) ;
2013-05-25 16:26:22 +00:00
wiki . addTiddler ( {
title : "a fourth tiddler" ,
text : "The quality of mercy is not drained by [[Tiddler Three]]" ,
2013-05-27 16:59:47 +00:00
tags : [ ] ,
2020-04-25 14:22:24 +00:00
cost : "82" ,
value : "72" ,
2017-02-22 12:13:59 +00:00
empty : "not" ,
2019-12-19 13:38:09 +00:00
modifier : "John" } ) ;
2013-08-07 15:06:46 +00:00
wiki . addTiddler ( {
title : "one" ,
text : "This is the text of tiddler [[one]]" ,
list : "[[Tiddler Three]] [[TiddlerOne]]" ,
2017-02-22 12:13:59 +00:00
empty : "" ,
2019-12-19 13:38:09 +00:00
modifier : "John" } ) ;
wiki . addTiddler ( {
title : "hasList" ,
text : "This is the text of tiddler [[hasList]]" ,
list : "[[Tiddler Three]] [[TiddlerOne]]" ,
modifier : "PMario" } ) ;
wiki . addTiddler ( {
title : "has filter" ,
text : "This is the text of tiddler [[has filter]]" ,
filter : "[[Tiddler Three]] [[TiddlerOne]] [subfilter{hasList!!list}]" ,
modifier : "PMario" } ) ;
wiki . addTiddler ( {
title : "filter regexp test" ,
text : "Those strings have been used to create the `regexp = /[+|\-|~]?([[](?:[^\]])*\]+)|([+|-|~|\S]\S*)/;`" ,
filter : "+aaa -bbb ~ccc aaaaaabbbbbbbbaa \"bb'b\" 'cc\"c' [[abc]] [[tiddler with spaces]] [is[test]] [is[te st]] a s df [enlist<hugo>] +[enlist:raw{test with spaces}] [enlist:raw{test with spaces}] [[a a]] [[ ] [ ]] [[ [hugo]] [subfilter{Story/Tower of Hanoi/A-C Sequence}]" ,
modifier : "PMario" } ) ;
2019-07-16 15:53:37 +00:00
// Unpack plugin tiddlers
wiki . readPluginInfo ( ) ;
wiki . registerPluginTiddlers ( "plugin" ) ;
wiki . unpackPluginTiddlers ( ) ;
wiki . addIndexersToWiki ( ) ;
2019-05-24 20:07:37 +00:00
return wiki ;
}
2013-05-25 16:26:22 +00:00
2019-05-24 20:07:37 +00:00
// Our tests
function runTests ( wiki ) {
2013-05-25 16:26:22 +00:00
2019-12-19 13:38:09 +00:00
it ( "should handle the enlist operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[enlist[one two three]addsuffix[!]]" ) . join ( "," ) ) . toBe ( "one!,two!,three!" ) ;
} ) ;
2020-11-01 17:11:46 +00:00
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 ( "" ) ;
} ) ;
2019-08-02 13:27:58 +00:00
it ( "should handle the then and else operators" , function ( ) {
2019-12-19 13:38:09 +00:00
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" ) ;
expect ( wiki . filterTiddlers ( "[modifier[DaveBloggs]then[Susi]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[modifier[JoeBloggs]else[Susi]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[!modifier[JoeBloggs]else[Susi]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[modifier[DaveBloggs]else[Susi]]" ) . join ( "," ) ) . toBe ( "Susi" ) ;
2019-08-02 13:27:58 +00:00
} ) ;
2018-11-20 13:29:44 +00:00
it ( "should handle the ~ prefix" , function ( ) {
expect ( wiki . filterTiddlers ( "[modifier[JoeBloggs]] ~[[No such tiddler]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[modifier[Susi]] ~[[No such tiddler]]" ) . join ( "," ) ) . toBe ( "No such tiddler" ) ;
2018-11-20 13:29:44 +00:00
expect ( wiki . filterTiddlers ( "~[[No such tiddler]]" ) . join ( "," ) ) . toBe ( "No such tiddler" ) ;
expect ( wiki . filterTiddlers ( "[my-field[present]] ~[[No such tiddler]]" ) . join ( "," ) ) . toBe ( "No such tiddler" ) ;
} ) ;
2017-09-07 14:48:00 +00:00
it ( "should handle the lookup operator" , function ( ) {
expect ( wiki . filterTiddlers ( "Six Seventh 8 +[lookup[Tiddler]]" ) . join ( "," ) ) . toBe ( "Missing inaction from TiddlerOne,,Tidd" ) ;
expect ( wiki . filterTiddlers ( "Six Seventh 8 +[lookup:8[Tiddler]]" ) . join ( "," ) ) . toBe ( "Missing inaction from TiddlerOne,Tidd,Tidd" ) ;
} ) ;
2014-03-17 10:50:18 +00:00
it ( "should retrieve shadow tiddlers" , function ( ) {
expect ( wiki . getTiddlerText ( "Tiddler8" ) ) . toBe ( "Tidd" ) ;
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the title operator" , function ( ) {
expect ( wiki . filterTiddlers ( "TiddlerOne [title[$:/TiddlerTwo]] [[Tiddler Three]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!title[Tiddler Three]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2013-05-25 16:26:22 +00:00
expect ( wiki . filterTiddlers ( "TiddlerOne [title[$:/TiddlerTwo]] [[Tiddler Three]] [[A Missing Tiddler]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three,A Missing Tiddler" ) ;
} ) ;
it ( "should handle the field operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!is[system]!modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2014-01-24 19:15:34 +00:00
expect ( wiki . filterTiddlers ( "[field:modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!field:modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!is[system]!field:modifier[JoeBloggs]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[modifier[John]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one" ) ;
expect ( wiki . filterTiddlers ( "[!modifier[John]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!is[system]!modifier[John]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[field:modifier[John]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one" ) ;
expect ( wiki . filterTiddlers ( "[!field:modifier[John]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!is[system]!field:modifier[John]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,hasList,has filter,filter regexp test" ) ;
2014-01-24 19:15:34 +00:00
} ) ;
2014-09-09 14:57:41 +00:00
it ( "should handle the regexp operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[regexp[id]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!regexp[id]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,one,hasList,has filter,filter regexp test" ) ;
2014-09-09 14:57:41 +00:00
expect ( wiki . filterTiddlers ( "[regexp[Tid]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[regexp[(?i)Tid]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!regexp[Tid(?i)]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,one,hasList,has filter,filter regexp test" ) ;
2014-09-09 14:57:41 +00:00
} ) ;
2019-12-19 13:38:09 +00:00
// The following 2 tests should write a log -> WARNING: Filter modifier has a deprecated regexp operand XXXX
// The test should pass anyway.
2014-01-24 19:15:34 +00:00
it ( "should handle the field operator with a regular expression operand" , function ( ) {
expect ( wiki . filterTiddlers ( "[modifier/JoeBloggs/]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[modifier/Jo/]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the prefix operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[prefix[Tiddler]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[prefix[nothing]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
it ( "should handle the sort and sortcs operators" , function ( ) {
2019-12-19 13:38:09 +00:00
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" ) ;
2014-05-16 13:46:55 +00:00
// 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");
2013-05-25 16:26:22 +00:00
} ) ;
2014-01-25 17:44:14 +00:00
it ( "should handle the reverse, first, last, butfirst, butlast, rest and nth operators" , function ( ) {
2019-07-16 15:53:37 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]first[]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]first[2]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]first[8]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three" ) ;
2019-07-16 15:53:37 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]first[x]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin" ) ;
2014-01-25 17:44:14 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]last[]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]last[2]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]last[8]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2014-01-25 17:44:14 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]last[x]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]reverse[]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]reverse[x]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,Tiddler Three,one,hasList,has filter,filter regexp test,a fourth tiddler,$:/TiddlerTwo,$:/ShadowPlugin" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]butlast[]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]butlast[2]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]butlast[11]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]butlast[x]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]rest[]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]rest[2]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]rest[11]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]rest[x]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2019-07-16 15:53:37 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]nth[]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin" ) ;
expect ( wiki . filterTiddlers ( "[sort[title]nth[2]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]nth[11]]" ) . join ( "," ) ) . toBe ( "" ) ;
2019-07-16 15:53:37 +00:00
expect ( wiki . filterTiddlers ( "[sort[title]nth[x]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin" ) ;
2014-01-25 17:44:14 +00:00
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the tag operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[tag[one]sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!tag[one]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one" ) ;
2013-05-25 16:26:22 +00:00
expect ( wiki . filterTiddlers ( "[prefix[Tidd]tag[one]sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[!is[shadow]tag[two]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three" ) ;
2014-04-03 19:49:16 +00:00
expect ( wiki . filterTiddlers ( "[all[shadows]tag[two]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
2019-07-28 15:39:34 +00:00
it ( "should handle the all operator with field, has and tag operators" , function ( ) {
expect ( wiki . filterTiddlers ( "[all[shadows]tag[two]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive" ) ;
expect ( wiki . filterTiddlers ( "[all[shadows+tiddlers]tag[two]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive,$:/TiddlerTwo,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[all[tiddlers+shadows]tag[two]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,$:/TiddlerFive" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[all[shadows+tiddlers]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8,$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[all[tiddlers+shadows]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test,$:/TiddlerFive,TiddlerSix,TiddlerSeventh,Tiddler8" ) ;
2019-07-28 15:39:34 +00:00
expect ( wiki . filterTiddlers ( "[all[tiddlers]tag[two]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three" ) ;
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the tags operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[tags[]sort[title]]" ) . join ( "," ) ) . toBe ( "one,two" ) ;
expect ( wiki . filterTiddlers ( "[[TiddlerOne]tags[]sort[title]]" ) . join ( "," ) ) . toBe ( "one" ) ;
} ) ;
2019-07-31 08:11:12 +00:00
it ( "should handle the match operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[match[TiddlerOne]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "TiddlerOne TiddlerOne =[match[TiddlerOne]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!match[TiddlerOne]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2019-07-31 08:11:12 +00:00
expect ( wiki . filterTiddlers ( "[match:casesensitive[tiddlerone]]" ) . join ( "," ) ) . toBe ( "" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!match:casesensitive[tiddlerone]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2019-07-31 08:11:12 +00:00
expect ( wiki . filterTiddlers ( "[match:caseinsensitive[tiddlerone]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!match:caseinsensitive[tiddlerone]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2019-07-31 08:11:12 +00:00
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the tagging operator" , function ( ) {
2015-01-27 17:20:03 +00:00
expect ( wiki . filterTiddlers ( "[[one]tagging[]sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,Tiddler8,TiddlerOne,TiddlerSeventh" ) ;
2015-03-11 21:58:45 +00:00
expect ( wiki . filterTiddlers ( "[[one]tagging[]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne,TiddlerSeventh,Tiddler8" ) ;
2014-03-11 15:53:41 +00:00
expect ( wiki . filterTiddlers ( "[[two]tagging[]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive,$:/TiddlerTwo,Tiddler Three" ) ;
2014-04-27 20:58:41 +00:00
var fakeWidget = { getVariable : function ( ) { return "one" ; } } ;
2015-03-11 21:58:45 +00:00
expect ( wiki . filterTiddlers ( "[all[current]tagging[]]" , fakeWidget ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne,TiddlerSeventh,Tiddler8" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
2013-09-14 15:28:46 +00:00
it ( "should handle the untagged operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[untagged[]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,a fourth tiddler,filter regexp test,has filter,hasList,one" ) ;
2013-09-14 15:28:46 +00:00
expect ( wiki . filterTiddlers ( "[!untagged[]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,TiddlerOne" ) ;
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the links operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[shadow]links[]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,has filter,hasList,one,Tiddler Three,TiddlerSix,TiddlerZero" ) ;
2014-04-03 19:49:16 +00:00
expect ( wiki . filterTiddlers ( "[all[shadows]links[]sort[title]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the backlinks operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[shadow]backlinks[]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,has filter,hasList,one,TiddlerOne" ) ;
2014-04-03 19:49:16 +00:00
expect ( wiki . filterTiddlers ( "[all[shadows]backlinks[]sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the has operator" , function ( ) {
2013-05-27 16:59:47 +00:00
expect ( wiki . filterTiddlers ( "[has[modified]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!has[modified]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,a fourth tiddler,filter regexp test,has filter,hasList,one" ) ;
2020-05-14 12:57:12 +00:00
expect ( wiki . filterTiddlers ( "[has[tags]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[!has[tags]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,a fourth tiddler,filter regexp test,has filter,hasList,one" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
2017-02-22 12:13:59 +00:00
it ( "should handle the has:field operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[has:field[empty]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,one" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!has:field[empty]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,filter regexp test,has filter,hasList,Tiddler Three,TiddlerOne" ) ;
2017-02-22 12:13:59 +00:00
} ) ;
2013-05-25 16:26:22 +00:00
it ( "should handle the limit operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[system]sort[title]limit[2]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,filter regexp test" ) ;
2013-05-25 16:26:22 +00:00
expect ( wiki . filterTiddlers ( "[prefix[Tid]sort[title]limit[1]]" ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
2013-10-01 10:27:26 +00:00
expect ( wiki . filterTiddlers ( "[prefix[Tid]sort[title]!limit[1]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the list operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,MissingTiddler,Tiddler Three,TiddlerOne" ) ;
2014-04-03 19:49:16 +00:00
expect ( wiki . filterTiddlers ( "[tag[one]list[TiddlerSeventh]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,MissingTiddler,Tiddler Three,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
2019-12-19 13:38:09 +00:00
it ( "should handle the next operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[[Tiddler Three]next[TiddlerSeventh]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler" ) ;
expect ( wiki . filterTiddlers ( "[[MissingTiddler]next[TiddlerSeventh]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
2013-09-22 09:02:40 +00:00
2019-12-19 13:38:09 +00:00
it ( "should handle the previous operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[[Tiddler Three]previous[TiddlerSeventh]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[[TiddlerOne]previous[TiddlerSeventh]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
2013-09-22 09:02:40 +00:00
2013-05-27 16:59:47 +00:00
it ( "should handle the search operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[search[the]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[search{Tiddler8}sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2018-10-30 17:39:18 +00:00
expect ( wiki . filterTiddlers ( "[search:modifier[og]sort[title]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[search:modifier,authors:casesensitive[Do]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo" ) ;
2018-10-30 17:39:18 +00:00
expect ( wiki . filterTiddlers ( "[search:modifier,authors:casesensitive[do]sort[title]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[search:authors:casesensitive,whitespace[John Doe]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[search:modifier:regexp[(d|bl)o(ggs|e)]sort[title]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[search:-modifier,authors:[g]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,filter regexp test,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[search:*:[g]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,filter regexp test,Tiddler Three,TiddlerOne" ) ;
2019-07-31 20:36:12 +00:00
expect ( wiki . filterTiddlers ( "[search:text:anchored[the]]" ) . join ( "," ) ) . toBe ( "TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler" ) ;
2013-05-27 16:59:47 +00:00
} ) ;
2018-12-17 11:19:48 +00:00
it ( "should yield search results that have search tokens spread across different fields" , function ( ) {
expect ( wiki . filterTiddlers ( "[search[fox one]sort[title]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
} ) ;
2013-05-27 16:59:47 +00:00
it ( "should handle the each operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[each[modifier]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,hasList,TiddlerOne" ) ;
2015-11-13 10:07:24 +00:00
expect ( wiki . filterTiddlers ( "[each:list-item[tags]sort[title]]" ) . join ( "," ) ) . toBe ( "one,two" ) ;
expect ( wiki . filterTiddlers ( "[each:list-item[authors]sort[title]]" ) . join ( "," ) ) . toBe ( "Bloggs,Joe,John Doe" ) ;
2013-05-27 16:59:47 +00:00
} ) ;
it ( "should handle the eachday operator" , function ( ) {
2013-09-21 09:07:49 +00:00
expect ( wiki . filterTiddlers ( "[eachday[modified]sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
2013-05-27 16:59:47 +00:00
} ) ;
it ( "should handle the sameday operator" , function ( ) {
2014-01-30 06:11:54 +00:00
expect ( wiki . filterTiddlers ( "[sameday[201304152200]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
describe ( "testing the is operator" , function ( ) {
it ( "should handle the '[is[current]]' operator" , function ( ) {
2014-04-27 20:58:41 +00:00
var fakeWidget = { getVariable : function ( ) { return "Tiddler Three" ; } } ;
expect ( wiki . filterTiddlers ( "[is[current]]" , fakeWidget ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[[Tiddler Three]is[current]]" , fakeWidget ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[[$:/TiddlerTwo]is[current]]" , fakeWidget ) . join ( "," ) ) . toBe ( "" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[current]sort[title]]" , fakeWidget ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the '[is[system]]' operator" , function ( ) {
2019-07-16 15:53:37 +00:00
expect ( wiki . filterTiddlers ( "[is[system]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[system]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the '[is[shadow]]' operator" , function ( ) {
2014-04-03 19:49:16 +00:00
expect ( wiki . filterTiddlers ( "[all[shadows]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerFive,Tiddler8,TiddlerSeventh,TiddlerSix" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[shadow]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the '[is[missing]]' operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[all[]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,TiddlerOne,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,one,hasList,has filter,filter regexp test" ) ;
2015-01-11 16:44:51 +00:00
expect ( wiki . filterTiddlers ( "[all[missing]]" ) . join ( "," ) ) . toBe ( "TiddlerZero" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!is[missing]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,Tiddler Three,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
expect ( wiki . filterTiddlers ( "[[TiddlerOne]is[missing]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[[TiddlerZero]is[missing]]" ) . join ( "," ) ) . toBe ( "TiddlerZero" ) ;
expect ( wiki . filterTiddlers ( "[!title[Tiddler Three]is[missing]]" ) . join ( "," ) ) . toBe ( "" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!title[Tiddler Three]!is[missing]sort[title]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,a fourth tiddler,filter regexp test,has filter,hasList,one,TiddlerOne" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
it ( "should handle the '[is[orphan]]' operator" , function ( ) {
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[is[orphan]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,filter regexp test,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[!is[orphan]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,one,hasList,has filter" ) ;
2013-05-25 16:26:22 +00:00
expect ( wiki . filterTiddlers ( "[[TiddlerOne]is[orphan]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[[TiddlerOne]!is[orphan]]" ) . join ( "," ) ) . toBe ( "" ) ;
2019-12-19 13:38:09 +00:00
expect ( wiki . filterTiddlers ( "[!title[Tiddler Three]is[orphan]sort[title]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler,filter regexp test,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[!title[Tiddler Three]!is[orphan]]" ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,$:/TiddlerTwo,one,hasList,has filter" ) ;
2013-05-25 16:26:22 +00:00
} ) ;
} ) ;
it ( "should handle the operand prefixes" , function ( ) {
expect ( wiki . filterTiddlers ( "[prefix[Tiddler]] +[sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
} ) ;
2013-05-27 16:59:47 +00:00
it ( "should handle indirect operands" , function ( ) {
expect ( wiki . filterTiddlers ( "[prefix{Tiddler8}] +[sort[title]]" ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[modifier{Tiddler8!!test-field}] +[sort[title]]" ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
2014-04-27 20:58:41 +00:00
var fakeWidget = { getVariable : function ( ) { return "Tiddler Three" ; } } ;
expect ( wiki . filterTiddlers ( "[modifier{!!modifier}] +[sort[title]]" , fakeWidget ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,a fourth tiddler,one,Tiddler Three" ) ;
2013-05-27 16:59:47 +00:00
} ) ;
2014-07-25 14:26:44 +00:00
it ( "should handle variable operands" , function ( ) {
var widget = require ( "$:/core/modules/widgets/widget.js" ) ;
// Create a root widget for attaching event handlers. By using it as the parentWidget for another widget tree, one can reuse the event handlers
2020-01-31 14:09:06 +00:00
var rootWidget = new widget . widget ( { type : "widget" , children : [ { type : "widget" , children : [ ] } ] } ,
{ wiki : wiki , document : $tw . document } ) ;
2014-07-25 14:26:44 +00:00
rootWidget . makeChildWidgets ( ) ;
var anchorWidget = rootWidget . children [ 0 ] ;
rootWidget . setVariable ( "myVar" , "Tidd" ) ;
rootWidget . setVariable ( "myVar2" , "JoeBloggs" ) ;
expect ( wiki . filterTiddlers ( "[prefix<myVar>] +[sort[title]]" , anchorWidget ) . join ( "," ) ) . toBe ( "Tiddler Three,TiddlerOne" ) ;
expect ( wiki . filterTiddlers ( "[modifier<myVar2>] +[sort[title]]" , anchorWidget ) . join ( "," ) ) . toBe ( "TiddlerOne" ) ;
} ) ;
2014-05-12 14:16:44 +00:00
it ( "should handle the before and after operators" , function ( ) {
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]after[TiddlerOne]]" ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]after[a fourth tiddler]]" ) . join ( "," ) ) . toBe ( "MissingTiddler" ) ;
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]after[MissingTiddler]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]before[TiddlerOne]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]before[a fourth tiddler]]" ) . join ( "," ) ) . toBe ( "Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "[list[TiddlerSeventh]before[MissingTiddler]]" ) . join ( "," ) ) . toBe ( "a fourth tiddler" ) ;
} ) ;
2019-02-07 11:18:53 +00:00
it ( "should handle the string operators" , function ( ) {
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[length[]]" ) . join ( "," ) ) . toBe ( "4,4,6,5" ) ;
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[uppercase[]]" ) . join ( "," ) ) . toBe ( "JOHN,PAUL,GEORGE,RINGO" ) ;
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[lowercase[]]" ) . join ( "," ) ) . toBe ( "john,paul,george,ringo" ) ;
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[split[]]" ) . join ( "," ) ) . toBe ( "J,o,h,n,P,a,u,l,G,e,o,r,g,e,R,i,n,g,o" ) ;
2019-06-21 09:36:53 +00:00
expect ( wiki . filterTiddlers ( "[[John. Paul. George. Ringo.]] +[split[.]trim[]]" ) . join ( "," ) ) . toBe ( "John,Paul,George,Ringo," ) ;
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[split[e]]" ) . join ( "," ) ) . toBe ( "John,Paul,G,org,,Ringo" ) ;
2019-02-07 12:48:23 +00:00
expect ( wiki . filterTiddlers ( "John Paul George Ringo +[join[ ]split[e]join[ee]split[ ]]" ) . join ( "," ) ) . toBe ( "John,Paul,Geeorgee,Ringo" ) ;
2020-04-14 16:49:38 +00:00
// Ensure that join doesn't return null if passed empty list
2020-09-24 17:37:51 +00:00
expect ( wiki . filterTiddlers ( "Test +[butlast[]join[ ]]" ) ) . toEqual ( [ ] ) ;
2020-04-14 16:49:38 +00:00
// Ensure that join correctly handles empty strings in source
expect ( wiki . filterTiddlers ( "[[]] Paul +[join[-]]" ) . join ( "," ) ) . toBe ( "-Paul" ) ;
2019-02-07 11:18:53 +00:00
expect ( wiki . filterTiddlers ( "[[ John ]] [[Paul ]] [[ George]] Ringo +[trim[]join[-]]" ) . join ( "," ) ) . toBe ( "John-Paul-George-Ringo" ) ;
2020-08-29 11:27:58 +00:00
expect ( wiki . filterTiddlers ( "[[ abc ]] [[def ]] [[ ghi]] +[trim[]]" ) . join ( "," ) ) . toBe ( "abc,def,ghi" ) ;
expect ( wiki . filterTiddlers ( "[[ abc ]] [[def ]] [[ ghi]] +[trim:prefix[]]" ) . join ( "," ) ) . toBe ( "abc ,def ,ghi" ) ;
expect ( wiki . filterTiddlers ( "[[ abc ]] [[def ]] [[ ghi]] +[trim:suffix[]]" ) . join ( "," ) ) . toBe ( " abc,def, ghi" ) ;
expect ( wiki . filterTiddlers ( "[[ abacus ]] [[ baobab ]] +[trim[ab]]" ) . join ( "," ) ) . toBe ( " abacus , baobab " ) ;
expect ( wiki . filterTiddlers ( "[[ abacus ]] [[ baobab ]] +[trim[a]]" ) . join ( "," ) ) . toBe ( " abacus , baobab " ) ;
expect ( wiki . filterTiddlers ( "abacus baobab +[trim[a]]" ) . join ( "," ) ) . toBe ( "bacus,baobab" ) ;
expect ( wiki . filterTiddlers ( "abacus baobab +[trim[ab]]" ) . join ( "," ) ) . toBe ( "acus,baob" ) ;
expect ( wiki . filterTiddlers ( "abacus baobab +[trim:prefix[ab]]" ) . join ( "," ) ) . toBe ( "acus,baobab" ) ;
expect ( wiki . filterTiddlers ( "abacus baobab +[trim:suffix[ab]]" ) . join ( "," ) ) . toBe ( "abacus,baob" ) ;
// Trim doesn't hiccup on regexp special characters
expect ( wiki . filterTiddlers ( "[[.*abacus.*]] [[.+baobab.+]] +[trim[.*]]" ) . join ( "," ) ) . toBe ( "abacus,.+baobab.+" ) ;
expect ( wiki . filterTiddlers ( "[[.*abacus.*]] [[.+baobab.+]] +[trim[.+]]" ) . join ( "," ) ) . toBe ( ".*abacus.*,baobab" ) ;
2019-02-07 11:18:53 +00:00
} ) ;
it ( "should handle the mathematics operators" , function ( ) {
2019-02-06 14:19:55 +00:00
expect ( wiki . filterTiddlers ( "[[2]add[2]]" ) . join ( "," ) ) . toBe ( "4" ) ;
expect ( wiki . filterTiddlers ( "[[4]subtract[2]]" ) . join ( "," ) ) . toBe ( "2" ) ;
expect ( wiki . filterTiddlers ( "[[24]divide[8]]" ) . join ( "," ) ) . toBe ( "3" ) ;
expect ( wiki . filterTiddlers ( "[[355]divide[113]sign[]multiply[4]]" ) . join ( "," ) ) . toBe ( "4" ) ;
expect ( wiki . filterTiddlers ( "[[355]divide[113]add[0.5]round[]multiply[4]]" ) . join ( "," ) ) . toBe ( "16" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[sum[]]" ) . join ( "," ) ) . toBe ( "10" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[product[]]" ) . join ( "," ) ) . toBe ( "24" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[maxall[]]" ) . join ( "," ) ) . toBe ( "4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[minall[]]" ) . join ( "," ) ) . toBe ( "1" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[max[2]]" ) . join ( "," ) ) . toBe ( "2,2,3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[min[2]]" ) . join ( "," ) ) . toBe ( "1,2,2,2" ) ;
} ) ;
2020-01-31 14:09:06 +00:00
/* listops filters */
2019-06-11 08:38:14 +00:00
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:include[]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter[1]]" ) . join ( "," ) ) . toBe ( "2,3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter:include[1]]" ) . join ( "," ) ) . toBe ( "1,2,3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter[2]]" ) . join ( "," ) ) . toBe ( "3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter:include[2]]" ) . join ( "," ) ) . toBe ( "2,3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter[3]]" ) . join ( "," ) ) . toBe ( "4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter:include[3]]" ) . join ( "," ) ) . toBe ( "3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter[4]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter:include[4]]" ) . join ( "," ) ) . toBe ( "4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter[5]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allafter:include[5]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
it ( "should handle the allbefore operator" , function ( ) {
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[1]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[1]]" ) . join ( "," ) ) . toBe ( "1" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[2]]" ) . join ( "," ) ) . toBe ( "1" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[2]]" ) . join ( "," ) ) . toBe ( "1,2" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[3]]" ) . join ( "," ) ) . toBe ( "1,2" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[3]]" ) . join ( "," ) ) . toBe ( "1,2,3" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[4]]" ) . join ( "," ) ) . toBe ( "1,2,3" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[4]]" ) . join ( "," ) ) . toBe ( "1,2,3,4" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore[5]]" ) . join ( "," ) ) . toBe ( "" ) ;
expect ( wiki . filterTiddlers ( "1 2 3 4 +[allbefore:include[5]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
2020-01-31 14:09:06 +00:00
it ( "should handle the append operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[append[d e]]" ) . join ( "," ) ) . toBe ( "a,b,c,d,e" ) ;
expect ( wiki . filterTiddlers ( "a b c +[append:1[d e]]" ) . join ( "," ) ) . toBe ( "a,b,c,d" ) ;
expect ( wiki . filterTiddlers ( "a b c +[append{TiddlerSeventh!!list}]" ) . join ( "," ) ) . toBe ( "a,b,c,TiddlerOne,Tiddler Three,a fourth tiddler,MissingTiddler" ) ;
expect ( wiki . filterTiddlers ( "a b c +[append:2{TiddlerSeventh!!list}]" ) . join ( "," ) ) . toBe ( "a,b,c,TiddlerOne,Tiddler Three" ) ;
expect ( wiki . filterTiddlers ( "a [[b c]] +[append{TiddlerSix!!filter}]" ) . join ( "," ) ) . toBe ( "a,b c,one,a a,[subfilter{hasList!!list}]" ) ;
} ) ;
it ( "should handle the insertbefore operator" , function ( ) {
var widget = require ( "$:/core/modules/widgets/widget.js" ) ;
var rootWidget = new widget . widget ( { type : "widget" , children : [ { type : "widget" , children : [ ] } ] } ,
{ wiki : wiki , document : $tw . document } ) ;
rootWidget . makeChildWidgets ( ) ;
var anchorWidget = rootWidget . children [ 0 ] ;
rootWidget . setVariable ( "myVar" , "c" ) ;
rootWidget . setVariable ( "tidTitle" , "e" ) ;
rootWidget . setVariable ( "tidList" , "one tid with spaces" ) ;
expect ( wiki . filterTiddlers ( "a b c d e f +[insertbefore:myVar[f]]" , anchorWidget ) . join ( "," ) ) . toBe ( "a,b,f,c,d,e" ) ;
expect ( wiki . filterTiddlers ( "a b c d e f +[insertbefore:myVar<tidTitle>]" , anchorWidget ) . join ( "," ) ) . toBe ( "a,b,e,c,d,f" ) ;
expect ( wiki . filterTiddlers ( "a b c d e f +[insertbefore:myVar[gg gg]]" , anchorWidget ) . join ( "," ) ) . toBe ( "a,b,gg gg,c,d,e,f" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[insertbefore:myVar<tidList>]" , anchorWidget ) . join ( "," ) ) . toBe ( "a,b,one tid with spaces,c,d,e" ) ;
expect ( wiki . filterTiddlers ( "a b c d e f +[insertbefore:tidTitle{TiddlerOne!!tags}]" , anchorWidget ) . join ( "," ) ) . toBe ( "a,b,c,d,one,e,f" ) ;
// Next 2 tests do weired things, but will pass - there for compatibility reasons
expect ( wiki . filterTiddlers ( "a b c [[with space]] +[insertbefore[b]]" ) . join ( "," ) ) . toBe ( "a,c,with space,b" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[insertbefore:2[b]]" ) . join ( "," ) ) . toBe ( "a,c,d,e,b" ) ;
} ) ;
it ( "should handle the move operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c d e +[move[c]]" ) . join ( "," ) ) . toBe ( "a,b,d,c,e" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[move:2[c]]" ) . join ( "," ) ) . toBe ( "a,b,d,e,c" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[move:10[c]]" ) . join ( "," ) ) . toBe ( "a,b,d,e,c" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[move:-1[c]]" ) . join ( "," ) ) . toBe ( "a,c,b,d,e" ) ;
expect ( wiki . filterTiddlers ( "a b c d e +[move:-5[c]]" ) . join ( "," ) ) . toBe ( "c,a,b,d,e" ) ;
} ) ;
it ( "should handle the prepend operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[prepend[dd ee]]" ) . join ( "," ) ) . toBe ( "dd,ee,a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:3[ff gg]]" ) . join ( "," ) ) . toBe ( "ff,gg,a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:1[hh ii]]" ) . join ( "," ) ) . toBe ( "hh,a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:0[jj kk]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:-0[ll mm]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:-1[nn oo pp qq]]" ) . join ( "," ) ) . toBe ( "nn,oo,pp,a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:-2[rr ss tt uu]]" ) . join ( "," ) ) . toBe ( "rr,ss,a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:-4[rr ss tt uu]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[prepend:-5[vv ww xx yy]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
} ) ;
it ( "should handle the putafter operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter[b]]" ) . join ( "," ) ) . toBe ( "a,b,ee,c,dd" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter:1[b]]" ) . join ( "," ) ) . toBe ( "a,b,ee,c,dd" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter:2[b]]" ) . join ( "," ) ) . toBe ( "a,b,dd,ee,c" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter:3[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,dd,ee" ) ;
// It starts to duplicate elements
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter:4[b]]" ) . join ( "," ) ) . toBe ( "a,b,b,c,dd,ee" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[putafter:5[b]]" ) . join ( "," ) ) . toBe ( "a,b,a,b,c,dd,ee" ) ;
// There are only 5 elements in the input
expect ( wiki . filterTiddlers ( "a b c ff gg +[putafter:6[b]]" ) . join ( "," ) ) . toBe ( "a,b,a,b,c,ff,gg" ) ;
// -1 starts to "eat" elements for the left and duplicates b
expect ( wiki . filterTiddlers ( "a b c hh ii +[putafter:-1[b]]" ) . join ( "," ) ) . toBe ( "a,b,b,c,hh,ii" ) ;
// -2 moves c, hh, ii behind b, which is not visible
expect ( wiki . filterTiddlers ( "a b c hh ii +[putafter:-2[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,hh,ii" ) ;
// only ii is used from input and it's moved behind b
expect ( wiki . filterTiddlers ( "a b c hh ii +[putafter:-4[b]]" ) . join ( "," ) ) . toBe ( "a,b,ii,c,hh" ) ;
// wasting time, because there are only 5 elements
expect ( wiki . filterTiddlers ( "a b c hh ii +[putafter:-5[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,hh,ii" ) ;
// there are only 5 elements
expect ( wiki . filterTiddlers ( "a b c hh ii +[putafter:-10[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,hh,ii" ) ;
// use NAN uses default = 1
expect ( wiki . filterTiddlers ( "a b c jj kk +[putafter:NAN[b]]" ) . join ( "," ) ) . toBe ( "a,b,kk,c,jj" ) ;
} ) ;
it ( "should handle the putbefore operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c dd +[putbefore[b]]" ) . join ( "," ) ) . toBe ( "a,dd,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c ff +[putbefore:1[b]]" ) . join ( "," ) ) . toBe ( "a,ff,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c gg +[putbefore:2[b]]" ) . join ( "," ) ) . toBe ( "a,c,gg,b" ) ;
expect ( wiki . filterTiddlers ( "a b c [[g g]] +[putbefore:2[b]]" ) . join ( "," ) ) . toBe ( "a,c,g g,b" ) ;
// this one is strange
expect ( wiki . filterTiddlers ( "a b c ee +[putbefore:0[b]]" ) . join ( "," ) ) . toBe ( "a,a,b,c,ee" ) ;
// b is not part of the list anymore, so it will be appended at the end ???
expect ( wiki . filterTiddlers ( "a b c hh +[putbefore:3[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,hh" ) ;
expect ( wiki . filterTiddlers ( "a b c ii +[putbefore:4[b]]" ) . join ( "," ) ) . toBe ( "a,a,b,c,ii" ) ;
// ????
expect ( wiki . filterTiddlers ( "a b c ii +[putbefore:10[b]]" ) . join ( "," ) ) . toBe ( "a,a,b,c,ii" ) ;
expect ( wiki . filterTiddlers ( "a b c kk +[putbefore:-1[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,kk" ) ;
expect ( wiki . filterTiddlers ( "a b c ll +[putbefore:-2[b]]" ) . join ( "," ) ) . toBe ( "a,c,ll,b" ) ;
expect ( wiki . filterTiddlers ( "a b c mm +[putbefore:-3[b]]" ) . join ( "," ) ) . toBe ( "a,mm,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c nn +[putbefore:-10[b]]" ) . join ( "," ) ) . toBe ( "a,b,c,nn" ) ;
} ) ;
it ( "should handle the putfirst operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[putfirst[a b]]" ) . join ( "," ) ) . toBe ( "c,a,b" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst[]]" ) . join ( "," ) ) . toBe ( "c,a,b" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:2[]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:3[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:4[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:-0[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:-1[]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:-2[]]" ) . join ( "," ) ) . toBe ( "c,a,b" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putfirst:-4[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
} ) ;
it ( "should handle the putlast operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[putlast[d e]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast[]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:1[]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:2[]]" ) . join ( "," ) ) . toBe ( "c,a,b" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:3[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:4[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:-0[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:0[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:-1[]]" ) . join ( "," ) ) . toBe ( "c,a,b" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:-2[]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a b c +[putlast:-4[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
} ) ;
it ( "should handle the remove operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[remove[d e]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[remove[a]]" ) . join ( "," ) ) . toBe ( "b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[remove[c b a]]" ) . join ( "," ) ) . toBe ( "" ) ;
} ) ;
it ( "should handle the replace operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c dd +[replace[a]]" ) . join ( "," ) ) . toBe ( "dd,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[replace:2[a]]" ) . join ( "," ) ) . toBe ( "dd,ee,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[replace:5[c]]" ) . join ( "," ) ) . toBe ( "a,b,a,b,c,dd,ee" ) ;
// strange things happen.
expect ( wiki . filterTiddlers ( "a b c dd ee +[replace:-1[c]]" ) . join ( "," ) ) . toBe ( "a,b,b,c,dd,ee" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[replace:-2[c]]" ) . join ( "," ) ) . toBe ( "a,b,c,dd,ee" ) ;
expect ( wiki . filterTiddlers ( "a b c dd ee +[replace:-2[ee]]" ) . join ( "," ) ) . toBe ( "a,b,c,dd,c,dd,ee" ) ;
} ) ;
it ( "should handle the sortby operator" , function ( ) {
expect ( wiki . filterTiddlers ( "a b c +[sortby[d e]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "a b c +[sortby[b c a]]" ) . join ( "," ) ) . toBe ( "b,c,a" ) ;
expect ( wiki . filterTiddlers ( "aa a b c +[sortby[b c a cc]]" ) . join ( "," ) ) . toBe ( "aa,b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a bb b c +[sortby[b c a cc]]" ) . join ( "," ) ) . toBe ( "bb,b,c,a" ) ;
expect ( wiki . filterTiddlers ( "a bb cc b c +[sortby[b c a cc]]" ) . join ( "," ) ) . toBe ( "bb,b,c,a,cc" ) ;
expect ( wiki . filterTiddlers ( "b a b c +[sortby[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "b a b c +[sortby[a b b c]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "b a b c +[sortby[b a c b]]" ) . join ( "," ) ) . toBe ( "b,a,c" ) ;
} ) ;
2020-11-01 10:45:18 +00:00
it ( "should handle the sortan operator" , function ( ) {
expect ( wiki . filterTiddlers ( "b a c +[sortan[]]" ) . join ( "," ) ) . toBe ( "a,b,c" ) ;
expect ( wiki . filterTiddlers ( "b2 a3 a1 b1 c2 a2 c3 b3 c1 +[sortan[]]" ) . join ( "," ) ) . toBe ( "a1,a2,a3,b1,b2,b3,c1,c2,c3" ) ;
expect ( wiki . filterTiddlers ( "b2 a10 c10 a1 b1 c2 a2 b10 c1 +[sortan[]]" ) . join ( "," ) ) . toBe ( "a1,a2,a10,b1,b2,b10,c1,c2,c10" ) ;
expect ( wiki . filterTiddlers ( "TiddlerOne $:/TiddlerTwo [[Tiddler Three]] +[sortan[]]" ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,TiddlerOne" ) ;
} ) ;
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" ) ;
} ) ;
2020-05-09 14:54:44 +00:00
it ( "should handle the slugify operator" , function ( ) {
expect ( wiki . filterTiddlers ( "[[Joe Bloggs]slugify[]]" ) . join ( "," ) ) . toBe ( "joe-bloggs" ) ;
expect ( wiki . filterTiddlers ( "[[Joe Bloggs2]slugify[]]" ) . join ( "," ) ) . toBe ( "joe-bloggs2" ) ;
expect ( wiki . filterTiddlers ( "[[@£$%^&*((]slugify[]]" ) . join ( "," ) ) . toBe ( "64-163-36-37-94-38-42-40-40" ) ;
expect ( wiki . filterTiddlers ( "One one ONE O!N!E +[slugify[]]" ) . join ( "," ) ) . toBe ( "one,one,one,one" ) ;
expect ( wiki . filterTiddlers ( "TiddlerOne $:/TiddlerTwo +[slugify[]]" ) . join ( "," ) ) . toBe ( "tiddler-one,tiddler-two" ) ;
} ) ;
2020-04-25 10:26:19 +00:00
it ( "should handle the sortsub operator" , function ( ) {
var widget = require ( "$:/core/modules/widgets/widget.js" ) ;
var rootWidget = new widget . widget ( { type : "widget" , children : [ { type : "widget" , children : [ ] } ] } ,
{ wiki : wiki , document : $tw . document } ) ;
rootWidget . makeChildWidgets ( ) ;
var anchorWidget = rootWidget . children [ 0 ] ;
rootWidget . setVariable ( "sort1" , "[length[]]" ) ;
rootWidget . setVariable ( "sort2" , "[get[text]else[]length[]]" ) ;
2020-04-25 14:22:24 +00:00
rootWidget . setVariable ( "sort3" , "[{!!value}divide{!!cost}]" ) ;
2020-04-25 10:26:19 +00:00
expect ( wiki . filterTiddlers ( "[sortsub:number<sort1>]" , anchorWidget ) . join ( "," ) ) . toBe ( "one,hasList,TiddlerOne,has filter,$:/TiddlerTwo,Tiddler Three,$:/ShadowPlugin,a fourth tiddler,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!sortsub:number<sort1>]" , anchorWidget ) . join ( "," ) ) . toBe ( "filter regexp test,a fourth tiddler,$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,TiddlerOne,has filter,hasList,one" ) ;
expect ( wiki . filterTiddlers ( "[sortsub:string<sort1>]" , anchorWidget ) . join ( "," ) ) . toBe ( "TiddlerOne,has filter,$:/TiddlerTwo,Tiddler Three,$:/ShadowPlugin,a fourth tiddler,filter regexp test,one,hasList" ) ;
expect ( wiki . filterTiddlers ( "[!sortsub:string<sort1>]" , anchorWidget ) . join ( "," ) ) . toBe ( "hasList,one,filter regexp test,a fourth tiddler,$:/ShadowPlugin,$:/TiddlerTwo,Tiddler Three,TiddlerOne,has filter" ) ;
expect ( wiki . filterTiddlers ( "[sortsub:number<sort2>]" , anchorWidget ) . join ( "," ) ) . toBe ( "one,TiddlerOne,hasList,has filter,a fourth tiddler,Tiddler Three,$:/TiddlerTwo,filter regexp test,$:/ShadowPlugin" ) ;
expect ( wiki . filterTiddlers ( "[!sortsub:number<sort2>]" , anchorWidget ) . join ( "," ) ) . toBe ( "$:/ShadowPlugin,filter regexp test,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,has filter,hasList,TiddlerOne,one" ) ;
expect ( wiki . filterTiddlers ( "[sortsub:string<sort2>]" , anchorWidget ) . join ( "," ) ) . toBe ( "one,TiddlerOne,hasList,has filter,$:/ShadowPlugin,a fourth tiddler,Tiddler Three,$:/TiddlerTwo,filter regexp test" ) ;
expect ( wiki . filterTiddlers ( "[!sortsub:string<sort2>]" , anchorWidget ) . join ( "," ) ) . toBe ( "filter regexp test,$:/TiddlerTwo,Tiddler Three,a fourth tiddler,$:/ShadowPlugin,has filter,hasList,TiddlerOne,one" ) ;
2020-04-25 14:22:24 +00:00
expect ( wiki . filterTiddlers ( "[[TiddlerOne]] [[$:/TiddlerTwo]] [[Tiddler Three]] [[a fourth tiddler]] +[!sortsub:number<sort3>]" , anchorWidget ) . join ( "," ) ) . toBe ( "$:/TiddlerTwo,Tiddler Three,TiddlerOne,a fourth tiddler" ) ;
2020-04-25 10:26:19 +00:00
} ) ;
2019-05-24 20:07:37 +00:00
}
2013-05-25 16:26:22 +00:00
} ) ;
} ) ( ) ;