Testing structured variables with C expressions
Component Testing for C
To initialize and test a structured variable or record, initialize or test all the fields using a list of native language expressions (one per field). The following example (taken from list.ptu) illustrates this form:
STR *l, init == , ev = {"myfoo",NIL,NIL}
Each element in the list must correspond to the structured variable field as it was declared.
Every expression in the list must obey the rules described so far, according to the type of field being initialized and tested:
-
An expression for simple fields or arrays of simple variables initialized using an expression
-
A list of expressions for array fields initialized using an enumerated list
-
A list of expressions for structured fields
Using Field Names in Native Expressions
You can specify field names in native expressions by following the field name of the structure with the characters "=>", as follows:
TEST 3
FAMILY nominal
ELEMENT
VAR l, init = NIL, ev = NONIL
VAR *l, init == , ev = {str=>"myfoo",next=>NIL,prev=>NIL}
VAR s, init = "myfoo", ev = init
#l = push(l,s);
END ELEMENT
END TEST
If you use this form, you do not have to respect the order of expressions in the list.
You can also use the position of the fields in the structure or record instead of the field names, on the basis that the field numbers begin at 1:
VAR *l, init ==, ev = {3 => NIL, 2 => NIL, 1 => "myfoo"}
As with arrays, you can also use a range for field positions, as follows:
VAR *l, init ==, ev = {1 => "myfoo", 2..3 => NIL}
Related Topics
Testing variables | Testing structured variables | Testing structured variables with other structured variables | C Unions | Omitting a Field's Initial and Test Values