Expressions
This is Tinderbox Cookbook version 2.0.0, created in conjunction with Tinderbox 5.9.3.
The locale settings used to export this document: en-GB. Most date tests were written/tested on a UK day/month order system and thus tests may fail if exported using different locale settings.
This page explores Tinderbox expressions, used in actions, rules, and with the export templates ^action()^ and ^value()^.
Deprecation. Some codes are now marked 'deprecated'. This means that while they may still work, such syntax should be avoided. New documents should not use such syntax and existing documents in regular use should be have their code reviewed to avoid retaining deprecated usage.
[Attribute]() - find value
Tests whether a regular expression can be found in a an attribute of a note.
Deprecated - use .contains/.icontains.
See the original tests on the deprecated code page.
| description | try | expect | result | ok |
|---|---|---|---|---|
| abs(5) | 5 | 5 | not yet | |
| abs(-5) | 5 | 5 | not yet | |
| abs(1-6) | 5 | 5 | not yet |
any()
scans each item of a group to see whether any of those items meets a criterion. Data are taken from the following example:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lemon | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
| any(child,$UserNum>100) | false | not yet | ||
logical |
any(child,$UserNum>10) | true | true | not yet |
| any(child(/data/fruit),$UserFlag) | true | true | not yet | |
| any(child(/data/fruit),$UserNum<0) | false | not yet | ||
Using a literal list of paths |
any("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserFlag) | true | true | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| atan(1) | 0.785398 | 0.785398 | not yet | |
| format(atan(0),2) | 0.00 | 0.00 | not yet | |
| atan(-1) | -0.785398 | -0.785398 | not yet |
attributeEncode
XML/OPML-safe encoding of attribute values:> The following characters are converted to numeric HTML entities (e.g. like ' '): left angle bracket, right angle bracket, ampersand, (straight) double quote, (straight) apostrophe, and line feed character (ASCII #10).
| description | try | expect | result | ok |
|---|---|---|---|---|
This is paragraph 1. This is paragraph 2. |
attributeEncode($Text) | This is paragraph 1. This is paragraph 2. | This is paragraph 1. This is paragraph 2. | not yet |
This 'is" <paragraph 1. This & is >paragraph 2. |
attributeEncode($Text) | This 'is" <paragraph 1. This & is >paragraph 2. | This 'is" <paragraph 1. This & is >paragraph 2. | not yet |
avg
Computers the mean of a numeric attribute for a group of notes. The data are the following:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
Computes the mean of all children |
avg(child,$UserNum) | 5.66667 | 5.66667 | not yet |
Computes the mean of the squares: 144+9+4 |
avg(child,$UserNum*$UserNum) | 52.3333 | 52.3333 | not yet |
Using a literal list of paths |
avg("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserNum) | 5.66667 | 5.66667 | not yet |
avg_if()
Computers the mean of a numeric attribute for a group of notes. The data are the following:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
Compute the means for only the children where $UserFlag is true |
avg_if(child,$UserFlag,$UserNum) | 7 | 7 | not yet |
Compute the means of only the children where $UserNum is less than 12 |
avg_if(child,$UserNum<12,$UserNum) | 2.5 | 2.5 | not yet |
Using a literal list of paths |
avg_if("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserFlag,$UserNum) | 7 | 7 | not yet |
between(value,min,max)
A value lies between a specified minimum and maximum. The value may be equal to min but must be less than max. Thus between 1 and 10, means 1.0 to 9.999...etc. and not 1.0 to 10.0.
| description | try | expect | result | ok |
|---|---|---|---|---|
True - 5 us between 1 and 10 |
between(5,1,10) | true | true | not yet |
True: 1 is within value range 1-10. |
between(1,1,10) | true | true | not yet |
True: 10 is not within range 1-10. |
between(10,1,10) | false | not yet | |
Expected fail |
between(1,5,10) | not yet | ||
$TestNumber = 5, $UserNum = 1, $UserNum2 = 10 |
between($TestNumber,$UserNum,$UserNum2) | true | true | not yet |
| between(dogs,cats,lions) | true | true | not yet | |
| between(cats,dogs,lions) | not yet | |||
| between("4/15/2009","4/1/2009","5/1/2009") | true | true | not yet | |
Test value matches min |
between("4/15/2009","4/15/2009","5/1/2009") | true | true | not yet |
Test value matches max. |
between("4/15/2009","4/1/2009","4/15/2009") | false | not yet | |
$TestDate = 15/04/2009, $Date = 01/04/2009, $Date2 = 01/05/2009 |
between($TestDate,$Date,$Date2) | true | true | not yet |
$TestDate = 15/02/2009, $Date = 01/04/2009, $Date2 = 01/05/2009 |
between($TestDate,$Date,$Date2) | false | not yet |
brightness(color)
return the relative brightness, on a scale of 0-100, of a color.
Deprecated - use Color.brightness.
See the original tests on the deprecated code page.
capitalize()
Transforms a string or attribute to use initial capitals.
| description | try | expect | result | ok |
|---|---|---|---|---|
Doing so causes the argument not to be processed |
capitalize("frosty friday") | Frosty Friday | Frosty Friday | not yet |
DEPRECATED - quote string literals. |
capitalize(frosty friday) | Frosty Friday | Frosty Friday | not yet |
Use a literal string. Only the initial letters are capitalised. |
capitalize("fROSTY fRIDAY") | FROSTY FRIDAY | FROSTY FRIDAY | not yet |
Use a literal string. Only the initial letters are capitalised. |
capitalize("frOSTy friDaY") | FrOSTy FriDaY | FrOSTy FriDaY | not yet |
Refer to value of $UserString from previous test. |
capitalize($UserString(prevSibling)) | Frosty Friday | Frosty Friday | not yet |
collect()
Construct a set of the unique values of an attribute of a collection of notes. Sample data are taken from the following:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lemon | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
| collect(child(/data/fruit),$Name) | apple;pear;lemon;lime | apple;pear;lemon;lime | not yet | |
collect() doesn't support explicit literal lists. |
collect("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$Name) | apple;pear;lemon;lime | apple;pear;lime | not yet |
Since v5.6 all 4 values are reported as collect() now returns a list not a (de-duped) set Note that pears and lemons have the same $UserNum. |
collect(child(/data/fruit),$UserNum) | 12;3;3;2 | 12;3;3;2 | not yet |
set should collect positive and negative numbers |
collect(child(/data/negatives),$UserNum) | 25;2;-0.5;-4 | 25;2;-0.5;-4 | not yet |
collect_if()
Construct a set of the unique values of an attribute of a collection of notes, filtered by an expression (the second parameter).
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
Collect only those items of the group that match the criterion |
collect_if(child(/data/fruit),$UserNum=3,$Name) | pear;lemon | pear;lemon | not yet |
collect only negative values |
collect_if(child(/data/negatives),$UserNum<0,$UserNum) | -0.5;-4 | -0.5;-4 | not yet |
collect_if() doesn't support explicit literal lists. |
collect_if(all,($Container=="/data/fruit/"),$Name) | apple;pear;lemon;lime | apple;pear;lemon;lime | not yet |
contains
tests whether a note is among this note's immediate children.
Sample data are taken from the following:
- fruit
- apple
- pear
- lemon
- lime
| description | try | expect | result | ok |
|---|---|---|---|---|
| eval(/data/fruit,contains("apple")) | true | true | not yet | |
|
$UserString(/data/fruit) = lemon About the test… ⇕ |
eval(/data/fruit,contains($UserString)) | true | true | not yet |
| eval(/data/fruit,contains("lion")) | false | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| format(cos(3.1415927/2),2) | -0.00 | -0.00 | not yet | |
| format(cos(3.1415927/4),3) | 0.707 | 0.707 | not yet | |
| format(cos(0),2) | 1.00 | 1.00 | not yet | |
| format(cos(0.5),2) | 0.88 | 0.88 | not yet |
count()
counts the number of items in a set
| description | try | expect | result | ok |
|---|---|---|---|---|
| count("lions;tigers;bears") | 3 | 3 | not yet |
date()
convert a string to a date, or construct a date from numeric values for year, month, and day. For the purposes of this test, $Date is 20 Jan 2009 00:00.
| description | try | expect | result | ok |
|---|---|---|---|---|
| date("28 November 2005 03:10") | 28/11/2005 03:10 | 28/11/2005 03:10 | not yet | |
| date($Date+1 day) | 21/01/2009 00:00 | 21/01/2009 00:00 | not yet | |
| date($Date+1 week) | 27/01/2009 00:00 | 27/01/2009 00:00 | not yet | |
| format(date(28 November 2005 03:10),"*") | Mon, 28 Nov 2005 03:10:00 +0100 | Mon, 28 Nov 2005 03:10:00 +0100 | not yet | |
Error because the time offest at time of conversion/export is being used rather than the offset for actual date (IOW it has a summer savings time offset for a winter date). |
format(date("$Date"),"*") | Tue, 20 Jan 2009 00:00:00 +0100 | Mon, 15 Aug 2011 16:05:00 +0100 | not yet |
Remember that summer dates should allow for offset using local summer daylight saving time |
format(date(28 June 2005 03:10),"*") | Tue, 28 Jun 2005 03:10:00 +0100 | Tue, 28 Jun 2005 03:10:00 +0100 | not yet |
| date(2001,2,3,4,5) | 03/02/2001 04:05 | 03/02/2001 04:05 | not yet |
day()
extract the day of the month from a date. Also, construct a date from an existing date, specifying the day of the month. For the purposes of this test, $Date is 20 Jan 2009 09:00
| description | try | expect | result | ok |
|---|---|---|---|---|
| day($Date) | 20 | 20 | not yet | |
$Date is 20 January 2009 |
day($Date,17) | 17/01/2009 09:00 | 17/01/2009 09:00 | not yet |
$UserNum is 24 |
day($Date,$UserNum) | 24/01/2009 09:00 | 24/01/2009 09:00 | not yet |
days()
compute the number of days between two dates.
| description | try | expect | result | ok |
|---|---|---|---|---|
$Date=20 Jan 2009 00:00. $Date2=20 Jan 2008 00:00. Note that this span includes a leap-year day in 2008. |
days($Date2,$Date) | 366 | 366 | not yet |
$Date=20 Jan 2009 00:00. $Date2=20 Jan 2008 00:00 |
days($Date,$Date2) | -366 | -366 | not yet |
| days("20/1/2008","20/1/2009") | 366 | 366 | not yet |
descendedFrom
tests whether the current note is a descendant of a named note.
Sample data are taken from the following:
- fruit
- apple
- pear
- lemon
- lime
| description | try | expect | result | ok |
|---|---|---|---|---|
| eval(/data/fruit/apple,descendedFrom("fruit")) | true | true | not yet | |
| eval(/data/fruit/apple,descendedFrom("/data")) | true | true | not yet | |
fruit is not descended from apple. |
eval(/data/fruit,descendedFrom("data/fruit/apple")) | false | not yet | |
| eval(/data/fruit/apple,descendedFrom("/NoSuchNote")) | false | not yet |
do
escapeHTML()
encode a string in a form suitable for HTML, replacing characters such as '<' and '&' with HTML entities.
| description | try | expect | result | ok |
|---|---|---|---|---|
| escapeHTML("<") | < | < | not yet | |
| escapeHTML("Gilbert & Sullivan") | Gilbert & Sullivan | Gilbert & Sullivan | not yet | |
The expression may be constructed from attribute references or strings. |
escapeHTML("Third "+"& "+ (1+2)) | Third & 3 | Third & 3 | not yet |
eval()
evaluates an expression
| description | try | expect | result | ok |
|---|---|---|---|---|
| eval("1+2") | 3 | 3 | not yet | |
| eval("$Name(grandparent)") | Expressions | Expressions | not yet | |
| eval(/data/fruit/apple,"$Name(parent)") | fruit | fruit | not yet |
every()
scan each item of a group to see whether all items meets a criterion. Compare any() and collect_if(). Data are taken from the following example:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lemon | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
every note has a positive $UserNum |
every(child(/data/fruit),$UserNum>0) | true | true | not yet |
but some notes have $UserNum less than ten |
every(child(/data/fruit),$UserNum>10) | not yet | ||
string comparison |
every(child(/data/fruit),$Name>"aardvark") | true | true | not yet |
Using a literal list of paths |
every("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserFlag) | false | not yet |
exportedString()
applies an export template to a note and returns the result as a string. exportedString() is occasionally useful as a bridge between the export template syntax and Tinderbox's action syntax.
| description | try | expect | result | ok |
|---|---|---|---|---|
This test has the title "example 1". |
exportedString(this,"^title^") | example 1 | example 1 | not yet |
| exportedString(this,"^title^ ^title(parent)^") | placeholder exportedString() | placeholder exportedString() | not yet |
find(query)
Returns a list of one or more path strings to matching items - so can match item or group scope with appropriate query argument.
| description | try | expect | result | ok |
|---|---|---|---|---|
Match a single item $TestList = find($Path=="/data/fruit/lime") |
$TestList | /data/fruit/lime | /data/fruit/lime | not yet |
Match all children of a container. Don't use inside() in this context as aliases of notes in the container are also found. $TestList = find($Container=="/data/fruit/") |
$TestList | /data/fruit/apple;/data/fruit/pear;/data/fruit/lemon;/data/fruit/lime | /data/fruit/apple;/data/fruit/pear;/data/fruit/lemon;/data/fruit/lime | not yet |
first
tests whether a note is among the first n notes in its container.
Sample data are taken from the following:
- fruit
- apple
- pear
- lemon
- lime
| description | try | expect | result | ok |
|---|---|---|---|---|
"apple" is the first child of "fruit" |
eval(/data/fruit/apple,first("/data/fruit",2)) | true | true | not yet |
"pear" is the second child of "fruit" |
eval(/data/fruit/pear,first("/data/fruit",2)) | true | true | not yet |
"lemon" is not among the first two children of "fruit" |
eval(/data/fruit/lemon,first("/data/fruit",2)) | false | not yet | |
There is no spoon |
eval(/data/fruit/spoon,first("/data/fruit",2)) | false | not yet |
format()
converts dates, strings, numbers, and sets to strings, with various options to determine the presentation of the formatted string.
| description | try | expect | result | ok |
|---|---|---|---|---|
set the number of digits after the decimal point |
format(3.1415927,2) | 3.14 | 3.14 | not yet |
the second argument is optional, and sets the total width of the field. Here, two spaces are added before the '3' to pad the field. |
"*"+format(3.1415927,2,6)+"*" | * 3.14* | * 3.14* | not yet |
format a set, using the delimiter you prefer. The value of $UserSet is dogs;cats;rabbits. |
format($UserSet,"•") | dogs•cats•rabbits | dogs•cats•rabbits | not yet |
format a date, using the date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 2009 00:00. |
format($Date,"W") | Tuesday | Tuesday | not yet |
format a date, using the date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 2009 00:00. |
format($Date,"L") | 20 January 2009 | 20 January 2009 | not yet |
format a date, using the date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 2009 00:00. |
format($Date,"l") | 20/01/2009 | 20/01/2009 | not yet |
format a date, using the date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 1709 00:00. |
format($Date,"l") | 20/01/1709 | 20/01/1709 | not yet |
format a date, using the RFC 822 date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 2009 15:47. Note the offset is that for 'today' and not the offset on the actual date. To get this sort of format for future or past dates without the offset consider using format($Date,"w, D M y h:mm:s"). |
format($Date,"*") | Tue, 20 Jan 2009 15:47:00 +0100 | Tue, 20 Jan 2009 15:47:00 +0100 | not yet |
format a date, using the ISO 8601 date format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 20 Jan 2009 15:47. |
format($Date,"=") | 2009-01-20T15:47:00+01:00 | 2009-01-20T15:47:00+01:00 | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 2 Apr 2009 09:23. |
format($Date,"d D m y Y w W M M0 MM") | 2 02 4 2009 09 Thu Thursday Apr 04 April | 2 02 4 2009 09 Thu Thursday Apr 04 April | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 11 May 2009 09:23. |
format($Date,"t") | 09:23 | 09:23 | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 11 May 2009 09:23. |
format($Date,"h:mm") | 09:23 | 09:23 | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 11 May 2009 09:23. |
format($Date,"h:mm:s") | 09:23:00 | 09:23:00 | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 11 May 2009 09:23. |
format($Date,"H:mm") | 9:23 | 9:23 | not yet |
format a date, using the time format string described in Appendix 5 of the Tinderbox User’s Manual. Here, $Date is 11 May 2009 09:23. |
format($Date,"H:mm p") | 9:23 AM | 9:23 AM | not yet |
hour()
extract the hour of the time from a date. Also, construct a date from an existing date, specifying the hour of the day. For the purposes of this test, $Date is never
| description | try | expect | result | ok |
|---|---|---|---|---|
| hour($Date) | 12 | 12 | not yet | |
$Date is 20 January 2001 |
hour($Date,12) | 20/01/2001 12:00 | 20/01/2001 12:00 | not yet |
$Date is 20 January 2001 : $UserNum is 12 |
hour($Date,$UserNum) | 20/01/2001 12:00 | 20/01/2001 12:00 | not yet |
hue(color)
computers the hue of a color, expressed as a color-wheel angle from 0 to 360°. Also, transforms a color by changing its hue while leaving its brightness and saturation unchanged.
Deprecated - use Color.hue.
See the original tests on the deprecated code page.
idEncode()
HTML and XML ID's must begin with a number or an underscore. Tinderbox's idEncode() makes it easy to use a $Name or other convenient text attribute as an ID.
| description | try | expect | result | ok |
|---|---|---|---|---|
| idEncode("33") | _33 | _33 | not yet | |
| idEncode("try this!") | try_this_ | try_this_ | not yet |
indented
returns true if the note is n generations removed from the top of the outline, or from specified ancestor. Useful, for example, for assigning different styles to top-level, secondary, and tertiary outline items.
Sample data are taken from the following:
- data
- fruit
- apple
- pear
- lemon
- lime
- fruit
| description | try | expect | result | ok |
|---|---|---|---|---|
OutlineDepth of apple is 3 |
eval(/data/fruit/apple,indented(2)) | true | true | not yet |
OutlineDepth of fruit is 2 |
eval(/data/fruit,indented(1)) | true | true | not yet |
apple is a child of fruit |
eval(/data/fruit/apple,indented(1,"/data/fruit") ) | true | true | not yet |
apple is a child of fruit |
eval(/data/fruit/apple,indented(2,"/data") ) | true | true | not yet |
inside
tests whether a note is one of the immediate children of a container.
Sample data are taken from the following:
- fruit
- apple
- pear
- lemon
- lime
| description | try | expect | result | ok |
|---|---|---|---|---|
| eval(/data/fruit/apple,inside("fruit")) | true | true | not yet | |
"apple" is not an immediate child of "/data" |
eval(/data/fruit/apple,inside("/data")) | false | not yet | |
fruit is not descended from apple. |
eval(/data/fruit,inside("data/fruit/apple")) | false | not yet | |
| eval(/data/fruit/apple,inside("/NoSuchNote")) | false | not yet |
jsonEncode()
This operator (added in v5.7.0) returns a JSON-encoded UTF-8 version of a string attribute's value. The apostrophe (straight single quote), straight double quote, solidus (forward slash) and backslash characters are all escaped by a preceding backslash character.
| description | try | expect | result | ok |
|---|---|---|---|---|
| $MyString.json() | Should escape \/solidus, \'single-, \"double-qoute and \\backslash | Should escape \/solidus, \'single-, \"double-qoute and \\backslash | not yet |
last
tests whether a note is among the last n notes in its container.
Sample data are taken from the following:
- fruit
- apple
- pear
- lemon
- lime
| description | try | expect | result | ok |
|---|---|---|---|---|
"lime" is the last child of "fruit" |
eval(/data/fruit/lime,last("/data/fruit",2)) | true | true | not yet |
"lemon" is the second to the last child of "fruit" |
eval(/data/fruit/lemon,last("/data/fruit",2)) | true | true | not yet |
"apple" is not among the last two children of "fruit" |
eval(/data/fruit/apple,last("/data/fruit",2)) | false | not yet | |
There is no spoon |
eval(/data/fruit/spoon,last("/data/fruit",2)) | false | not yet |
lastWord()
| description | try | expect | result | ok |
|---|---|---|---|---|
| lastWord("Winter is coming") | coming | coming | not yet | |
| lastWord($MyString)) | coming | coming | not yet | |
| lastWord($MyString(prevSibling)) | coming | coming | not yet |
linkFrom()
This function creates a link and returns nothing. It can't easily be tested in a cookbook context.
linkTo()
This function creates a link and returns nothing. It can't easily be tested in a cookbook context.
linkedFrom
tests linkage values among a collection of linked notes. The data are taken from the following example:
| description | try | expect | result | ok |
|---|---|---|---|---|
is Ralph linked from Amy? |
eval(/data/people/Ralph,linkedFrom("Amy")) | true | true | not yet |
is Louisa linked from Amy by a link of type 'special'? |
eval(/data/people/Louisa,linkedFrom("Amy","special")) | true | true | not yet |
linkedTo
tests linkage values among a collection of linked notes. The data are taken from the following example:
| description | try | expect | result | ok |
|---|---|---|---|---|
is Amy linked to David? |
eval(/data/people/Amy,linkedTo("David")) | true | true | not yet |
is Amy linked to Beth by a link of type 'special'? |
eval(/data/people/Amy,linkedTo("Beth","special")) | true | true | not yet |
links
creates a set of values among a collection of linked notes. The data are taken from the following example:
| description | try | expect | result | ok |
|---|---|---|---|---|
Collect the names of notes linked to Amy by links of type "special" |
links(/data/people/Amy).outbound.special.$Name | Beth;Louisa | Beth;Louisa | not yet |
Collect the names of notes from Amy regardless of type |
links(/data/people/Amy).outbound..$Name | Ralph;Jo;David;Beth;Louisa | Ralph;Jo;David;Beth;Louisa | not yet |
Collect the names of notes that link to David |
links(/data/people/David).inbound..$Name | Amy;Louisa | Amy;Louisa | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| log(2) | 0.693147 | 0.693147 | not yet | |
| log(2.7182818284) | 1 | 1 | not yet | |
| log(10) | 2.30259 | 2.30259 | not yet |
lowercase()
Transforms a string or attribute to use all lower case.
| description | try | expect | result | ok |
|---|---|---|---|---|
| lowercase("FROSTY FRIDAY") | frosty friday | frosty friday | not yet | |
$MyString = "FROSTY FRIDAY" |
lowercase($MyString) | frosty friday | frosty friday | not yet |
$MyString = "FROSTY FRIDAY" |
lowercase($MyString(prevSibling)) | frosty friday | frosty friday | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
If no context is provided, max() compares elements lexically unless every element is a number |
max(1;10;3) | 10 | 10 | not yet |
If no context is provided, max() compares elements lexically unless every element is a number |
max(1;10;zebra) | zebra | zebra | not yet |
|
Action: $UserNum=max(1;10;3) . Since max() has a numeric context, is sorts numerically |
$UserNum | 10 | 10 | not yet |
| max("Winken;Blinken;Nod") | Winken | Winken | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| min(apple;pear;grape) | apple | apple | not yet | |
|
Action: $UserNum=min(10;2;3) . Since our context is numeric, min() compares items numerically. |
$UserNum | 2 | 2 | not yet |
| min("Winken;Blinken;Nod") | Blinken | Blinken | not yet | |
Largest negative should be minimum value returned. |
min(20;2;-0.5;-4) | -4 | -4 | not yet |
|
Action: $UserNum=min(20;2;-0.5;-4) |
$UserNum | -4 | -4 | not yet |
Test that collect() is correctly passing through positive and negative values. |
min(collect(child(/data/negatives),$UserNum)) | -4 | -4 | not yet |
minute()
extract the minute of the time from a date. Also, construct a date from an existing date, specifying the minute of the day. For the purposes of this test, $Date is never
| description | try | expect | result | ok |
|---|---|---|---|---|
| minute($Date) | 44 | 44 | not yet | |
$Date is 20 January 2001 |
minute($Date,21) | 20/01/2001 09:21 | 20/01/2001 09:21 | not yet |
$Date is 20 January 2001 : $UserNum is 21 |
minute($Date,$UserNum) | 20/01/2001 09:21 | 20/01/2001 09:21 | not yet |
minutes()
Offset in minutes between two date/times.
| description | try | expect | result | ok |
|---|---|---|---|---|
| minutes($Date2,$Date) | 10 | 10 | not yet | |
| minutes($Date,$Date2) | -10 | -10 | not yet | |
| minutes(date("1/20/2009 15:20"),date("1/20/2009 15:25")) | 5 | 5 | not yet |
mod
Modulo arithmetic: divides the first argument by the second argument and returns the remainder.
Wiki: Math
| description | try | expect | result | ok |
|---|---|---|---|---|
| mod(5,2) | 1 | 1 | not yet | |
| mod(4,2) | 0 | 0 | not yet | |
| mod(3,100) | 3 | 3 | not yet |
month()
extracts the month (as a number from 1-12) from a date. With two arguments, converts a date to a new date, replacing the original date’s month by a new month.
| description | try | expect | result | ok |
|---|---|---|---|---|
| month("January 20, 2009") | 1 | 1 | not yet | |
$Date is 04/07/1985 16:40. |
month($Date) | 7 | 7 | not yet |
$Date is 04/07/1976 16:40. |
month($Date,9) | 04/09/1976 16:40 | 04/09/1976 16:40 | not yet |
$Date is 04/07/1976 00:00. |
month($Date,12+9) | 04/09/1977 00:00 | 04/09/1977 00:00 | not yet |
$Date is 14/07/1789 15:00. |
month($Date,month($Date)+12) | 14/07/1790 15:00 | 14/07/1790 15:00 | not yet |
$Date is 14/07/1985 16:44. In earlier versions, Tinderbox failed to treat the second argument as a number |
month($Date,month($Date)+12) | 14/07/1986 16:44 | 14/07/1986 16:44 | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| radians(180) | 3.14159 | 3.14159 | not yet | |
| radians(-90) | -1.5708 | -1.5708 | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| rand() | 0.487627 | not yet | ||
| rand() | 0.547479 | not yet | ||
a random integer from 0-99 |
round(100*rand()) | 49 | not yet |
rgb()
constructs a color from separate intensities of red, green, and blue, on a scale of 0-255.
| description | try | expect | result | ok |
|---|---|---|---|---|
50% gray |
rgb(128,128,128) | #808080 | #808080 | not yet |
dark red |
rgb(64,0,0) | #400000 | #400000 | not yet |
light green |
rgb(200,255,200) | #c8ffc8 | #c8ffc8 | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| round(4.3) | 4 | 4 | not yet | |
| round(-4.3) | -4 | -4 | not yet |
runCommand()
provides a link between Tinderbox actions and external programs. Executes a command-line process. The second argument, if supplied, is passed to the new process’ standard input, and the process' standard output is the result of the command.
| description | try | expect | result | ok |
|---|---|---|---|---|
| runCommand('ls','') | Applications | Applications Library Network System Tinderbox temp.tbx User Guides And Information Users Volumes bin cores dev etc home mach_kernel net pdfData.pdf private sbin tmp usr var | not yet | |
$URL is http://www.eastgate.com/Tinderbox/config/version This may need the 'Expected' value to be updated for the current version. If the 'result' column shows a valid (past) version number this test is, in effect, passed. |
runCommand("curl "+$URL) | 5.9 | 5.9.3 | not yet |
saturation(color)
computes the saturation of a color — the intensity of its hue, on a scale of 0 (completely neutral) to 100 (intensely saturated). Alternatively, creates a new color whose hue and brightness are unchanged, but with a new saturation.
Deprecated - use Color.saturation.
See the original tests on the deprecated code page.
similarTo
returns true if this note is similar to the named note.
| description | try | expect | result | ok |
|---|---|---|---|---|
But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. |
similarTo("/data/Gettysburg",10) | true | true | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| sin(0) | 0 | 0 | not yet | |
| sin(radians(90)) | 1 | 1 | not yet | |
| format(sin(radians(45)),3) | 0.707 | 0.707 | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| sqrt(4) | 2 | 2 | not yet | |
| sqrt(7*7) | 7 | 7 | not yet | |
| format(sqrt(2)*sqrt(2),2) | 2.00 | 2.00 | not yet | |
| sqrt(-2) | -nan | nan | not yet | |
| sqrt("Hecuba") | -nan | nan | not yet |
sum()
Adds a numeric attribute for a group of notes. The data are the following:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
Add the numeric attribute of each child |
sum(child,$UserNum) | 17 | 17 | not yet |
Using a literal list of paths |
sum("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserNum) | 17 | 17 | not yet |
We may sum an expression; here, we sum the squares of UserNum |
sum(child,$UserNum*$UserNum) | 157 | 157 | not yet |
sum_if()
Adds a numeric attribute for a group of notes. The data are the following:
| Name | UserFlag | UserNum |
|---|---|---|
| apple | true | 12 |
| pear | false | 3 |
| lime | true | 2 |
Wiki: Groups
| description | try | expect | result | ok |
|---|---|---|---|---|
Add the numeric attributes of selected children |
sum_if(child,$UserFlag,$UserNum) | 14 | 14 | not yet |
sum_if may also use an expression; here, we have the sum of those fruits of which we have less than a dozen |
sum_if(child,$UserNum<12,$UserNum) | 5 | 5 | not yet |
sum_if can count notes that meet a criterion; here, we count fruits of which we have less than a dozen. |
sum_if(child,$UserNum<12,1) | 2 | 2 | not yet |
Using a literal list of paths |
sum_if("/data/fruit/apple;/data/fruit/pear;/data/fruit/lime",$UserFlag,$UserNum) | 14 | 14 | not yet |
| description | try | expect | result | ok |
|---|---|---|---|---|
| tan(0) | 0 | 0 | not yet | |
| tan(radians(45)) | 1 | 1 | not yet |
time()
extract the time of day, as a string, from a date or date expression. Also, modify a date to set a specific time of day. In these examples, $Date is 20/01/2009.
| description | try | expect | result | ok |
|---|---|---|---|---|
Time is: 11:00 |
time($Date(parent)) | 11:00 | 11:00 | not yet |
Time is: 11:00 |
time($Date(parent)+"3 hours") | 14:00 | 14:00 | not yet |
Time is: 11:00 |
time($Date(parent),10,15) | 20/01/2009 10:15 | 20/01/2009 10:15 | not yet |
Time is: 11:00. $UserNum = 8. |
time($Date(parent),$UserNum,5+10) | 20/01/2009 08:15 | 20/01/2009 08:15 | not yet |
Time is: 11:00. $UserNum = 8. $UserNum2 = 10. |
time($Date(parent),$UserNum,5+$UserNum2) | 20/01/2009 08:15 | 20/01/2009 08:15 | not yet |
unlinkFrom()
This function deletes a link and returns nothing. It can't easily be tested in a cookbook context.
unlinkTo
This function deletes a link and returns nothing. It can't easily be tested in a cookbook context.
uppercase()
Transforms a string or attribute to use all upper case.
| description | try | expect | result | ok |
|---|---|---|---|---|
| uppercase("frosty friday") | FROSTY FRIDAY | FROSTY FRIDAY | not yet | |
$MyString = "frosty friday" |
uppercase($MyString) | FROSTY FRIDAY | FROSTY FRIDAY | not yet |
$MyString = "frosty friday" |
uppercase($MyString(prevSibling)) | FROSTY FRIDAY | FROSTY FRIDAY | not yet |
urlEncode
URLs may only contain a restricted character set. urlEncode() converts any illegal characters in a string to the appropriate representation; for example, a space is converted to the string %20.
| description | try | expect | result | ok |
|---|---|---|---|---|
| urlEncode("my test") | my%20test | my%20test | not yet | |
the argument to urlEncode() should be evaluated before the string is encoded. |
urlEncode($Name(child)) | foo%20bar | foo%20bar | not yet |
utf8("theString")
utf8("theString")
Deprecated - not needed as Tinderbox now outputs UTF-8 as the default encoding.
See the original tests on the deprecated code page.
word()
tests whether a word occurs in the text or title of a note. This is faster than regular expression search, but less flexible.
| description | try | expect | result | ok |
|---|---|---|---|---|
The word "score" is found in the Gettsburg address. |
eval(/data/Gettysburg,word("score")) | true | true | not yet |
The the phrase "Four score" appears, but it is not a word |
eval(/data/Gettysburg,word("Four score")) | false | not yet | |
The word "Gettysburg" is found in the title of the note containing the Gettsyburg address. |
eval(/data/Gettysburg,word("Gettysburg")) | true | true | not yet |
The phrase "Four score" can be found by regular expression search |
eval(/data/Gettysburg,"Text(Four score)") | true | true | not yet |
year()
extract the year from a date. Also, construct a date from an existing date, specifying the year. For the purposes of this test, $Date is never
| description | try | expect | result | ok |
|---|---|---|---|---|
| year($Date) | 2009 | 2009 | not yet | |
$Date is 20 January 2001 |
year($Date,2011) | 20/01/2011 09:00 | 20/01/2011 09:00 | not yet |
$Date is 20 January 2001 : $UserNum is 2011 |
year($Date,$UserNum) | 20/01/2011 09:00 | 20/01/2011 09:00 | not yet |