Testing Functions

The testfuncs tool enables entry of an expression in the iWay functional language. It evaluates the expression and returns the result. It is intended for technical users. To use the command, type:

Tool testfuncs <path to an xml document>

The tool supports the set subcommand to set a special register value. For example, assume you want to try how the special register works with arithmetic:

funcs->set aa 1
stored
funcs->sreg(aa)+2
<superroot [baseNode]>
   <arith [funcNodeMath]>+
      <sreg [funcNodeFunctionSreg]>sreg(aa)
         <p-literal [funcNodeLit]>aa</p-literal>
      </sreg>
      <x-literal [funcNodeLit]>2</x-literal>
   </arith>
</superroot>
3
funcs->

Another example might make it clearer:

funcs->_substr('abcde',2,4)
<superroot [baseNode]>
   <substr [funcNodeFunctionStr.substr]>_substr(&apos;abcde&apos;,2,4)
      <p-literal [funcNodeLit]>abcde</p-literal>
      <p-literal [funcNodeLit]>2</p-literal>
      <p-literal [funcNodeLit]>4</p-literal>
   </substr>
</superroot>
cd
funcs->

Each test shows the abstract syntax tree that results from the compile of the function. Problems with the compilation can usually be understood by analysis of the tree. Some function testing requires use of special registers. The following command sets the specified special register to the designated value.

set regname value

The value operand is evaluated, so that a value can, for example, reside in a file. If the value after evaluation begins with a left bracket, the test tool assumes that the value is to be parsed as XML and an XML tree is to be loaded into the named register. Otherwise, the register is set to a string of the input value. To set register one to the value valone, use:

funcs->set one valone
stored

A file in the root named sregdoc.xml contains an XML document. To load it into a special register named xmldoc, use the following command.

funcs->set xmldoc file('/sregdoc.xml')
stored xml

iWay Software