.. File: testin
..
.. test command file for tm.
.. Attempts an exhausive test of all functions and commands.

VARIABLES:
----
.set a 12
.set av z y x
.set z GOOD!
'$a'
'$(a)'
'$(${first $(av)})'
'$(iserniet)'
'$(a'
.set a
'$a'
'$(a)'
'$$' '$.' '$"'
.append av $(av)
.append unknownvariable bla bla bla
unknownvariable: '$(unknownvariable)'
'$(av)'
----
Special variables:
dollar: '$$'
dot: '$.'
double quote: '$"'

COMMANDS:
---------

if:
----
.if 1
if 1 done
.else
if 1 not done
.endif
----
.if 0
if 0 done
.else
if 0 not done
.endif
----
.if ""
if "" done
.else
if "" not done
.endif
----

insert:
----
.set var ladidah
var = `$(var)'
.insert testsub
var = `$(var)'
----

include:
----
.set var ladidah
var = `$(var)'
.include testsub
var = `$(var)'
----

copy:
----
.set var ladidah
var = `$(var)'
.copy testsub
var = `$(var)'
----

error:
----
.error
.error error message line
.set msg "this is a message line"
.error $(msg)
----

foreach:
----
.foreach i a b c d
$i
.endforeach
----
.foreach i
$i
.endforeach
----

while:
----
.set l 1 2 3 4 5 6 7
.while ${len $l}
$l
.set l ${shift $l}
.endwhile
----

FUNCTIONS:
----------

Comparison functions:
----
eq : '${eq a a }' '${eq 0 00}' '${eq a aaaaaa}'
neq: '${neq a a}' '${neq 0 00}' '${neq a aaaaa}'
strcmp: '${strcmp a a}' '${strcmp 0 00}' '${strcmp 00 0}' '${strcmp a aaaaa}'
== : '${== 3 3 }' '${== 3 5}' '${== 3 -3}' '${== 3 a}'
!= : '${!= 3 3 }' '${!= 3 5}' '${!= 3 -3}' '${!= 3 a}'
<  : '${< 4 5}' '${< 4 4}' '${< 2 1}'
<= : '${<= 4 5}' '${<= 4 4}' '${<= 2 1}'
>  : '${> 4 5}' '${> 4 4}' '${> 2 1}'
>= : '${>= 4 5}' '${>= 4 4}' '${>= 2 1}'
----

Aritmetic functions:
----
+: '${+ 1 2 3 4 5}' '${+ 3}' '${+}'
-: '${- 5 1}' '${- 1 5}' '${- 1}'
*: '${* 1 2 3 4 5}' '${* 3}' '${*}'
/: '${/ 12 3}' '${/ 11 3}' '${/ 13 3}' '${/ 3 13}'
%: '${% 12 3}' '${% 11 3}' '${% 13 3}' '${% 3 13}'
max: '${max -1 1 2 3 4 5}' '${max 3}' '${max}'
min: '${min -1 1 2 3 4 5}' '${min 3}' '${min}'
----

Boolean:
----
and: '${and 1 1 1}' '${and 0 1 1}' '${and}'
not: '${not 1}' '${not 0}' '${not ""}' '${not}'
or:  '${or 0 0 0 0}' '${or 1 0 0}' '${or}'
----

List manipulation:
----
.set lst a b c d e f
index:   '${index a $(lst)}' '${index z $(lst)}' '${index z}' '${index}'
shift:   '${shift $(lst)}' '${shift}'
first:   '${first $(lst)}' '${first}'
seplist: '${seplist ", " $(lst)}' '${seplist a a}' '${seplist a}'
prefix:  '${prefix pfx_ $(lst)}' '${prefix pfx_ a}' '${prefix pfx_}'
suffix:  '${suffix _sfx $(lst)}' '${suffix _sfx a}' '${suffix _sfx}'
len:     '${len $(lst)}' '${len a}' '${len}'
sort:    '${sort $(lst) $(lst)}' '${sort 1 2 12 -1}' '${sort }'
uniq:    '${uniq $(lst) $(lst)}' '${uniq 1 2 12 -1}' '${uniq }'
rev:     '${rev $(lst)}' '${rev}'

----
Regular expressions:
.set wildstring foobar fobar foo bar blabar a b barf foofoo barbar ian
.foreach fn subs filt
funtion: $(fn)
.foreach pats "foo* 1" "foo* &&" "(foo)* &\1"  "foo(*) &\1" "(foo)(*) \2\1"
$(pats): [${$(fn) $(pats) $(wildstring)}]
.endforeach
.foreach pats "[a-e]* !&" "(?)(*)(?) \3\2\1"
$(pats): [${$(fn) $(pats) $(wildstring)}]
.endforeach

.endforeach
funtion: rmlist
.foreach pats "foo*" "foo*" "(foo)*"  "foo(*)" "(foo)(*)" "[a-e]*" "(?)(*)(?)"
$(pats): [${rmlist $(pats) $(wildstring)}]
.endforeach

----
Filename access functions:
----
dsfilename: '${ dsfilename }'
tplfilename: '${ tplfilename }'
tpllineno: '${ tpllineno }'
----

Datastructure access functions:
----
typelist: '${typelist}'
ttypelist: '${ttypelist}'
ctypelist: '${ctypelist}'
.foreach t ${typelist}
    conslist $t: '${conslist $t }'
.foreach c ${conslist $t}
        celmlist: '${celmlist $t $c }'
.foreach e ${celmlist $t $c }
            ctypeclass $t $c $e: '${ctypeclass $t $c $e }'
            ctypename $t $c $e: '${ctypename $t $c $e }'
.endforeach
.endforeach
    telmlist $t: '${telmlist $t }'
.foreach e ${telmlist $t }
	ttypeclass $t $e: '${ttypeclass $t $e }'
	ttypename $t $e: '${ttypename $t $e }'
.endforeach
.endforeach
----

Datastructure dependency
----
single types dependent on ${first ${typelist}}:
'${deptype single ${first ${typelist}}}'
list types dependent on ${first ${typelist}}:
'${deptype list ${typelist}}'
Testing error handling:
'${deptype list}'
'${deptype reutel ${first ${typelist}}}'
'${deptype}'
----

String manipulation functions:
----
strpad: '${strpad bla 6 " "}' '${strpad abcdef 3 !}' '${strpad bla 11 wow}'
strpad: '${strpad "" 5 0}' '${strpad zwoing 10 ""}'
strlen: '${strlen <word> }' '${strlen ""}' '${strlen}'
strindex: '${strindex c abcdef}' '${strindex z abcdef}'
toupper: '${toupper bla}' '${toupper BLA}' '${toupper}'
tolower: '${tolower bla}' '${tolower BLA}' '${tolower}'
----

Miscellaneous functions:
----
.set yes
${defined yes} ${defined doesnotexist} ${defined}
----

verbose flag:
----
verbose = '$(verbose)'
----

.foreach fn comm excl
$(fn):
----
'${$(fn) a b c d e f a b c d e f "" a e g h a}'
'${$(fn) a b c d}'
'${$(fn) a b c d ""}'
'${$(fn) "" a b c d}'
----

.endforeach

Integer expressions
-------------------

'$[-12]' '$[--12]'
'$[12+-12]' '$[1+2+3+4+5+6+7]'
'$[12*12+13*13]' '$[1*2*3*4*5*6*7]' '$[12/12]' '$[42%13]'
.foreach op < <= > >= != ==
$(op): '$[1$(op)2]' '$[-1$(op)-2]' '$[-1$(op)2]' '$[1$(op)-2]' '$[-42$(op)-42]'
.endforeach
.foreach op | & == != < <= >= >
 $(op)
-------
.foreach a 0 1
.foreach b 0 1
$a $b | $[$a$(op)$b]
.endforeach
.endforeach

.endforeach
$[((12))]
'$[]' '$[12+]' '$[12'
'$[a]' '$[12/0]' '$[12%0]'

Buffer size test.
Create a list with 4k worth elements.
.set l 0123456789
.while $[${len $l}<400]
.set l $l $l
${len $l}
.endwhile
