// tutorial10.ot
group "tutorial_10";
table Table1(int, int, char*)
{
{ 3, 3, "Hello" },
{ 4, 54, "Hi" },
{ 5, 65, "Hej" },
{ 1, 100, "Hejsan" }
}
test("Iterate through a table")
{
iterate (a, b, c) from Table1
{
output("Testing, a = %d, b = %d, c == %s\n", a, b, c);
verify(a == 3 || a == 4 || a == 5 || a == 1);
verify(b == 3 || b == 54 || b == 65 || b == 100);
verify(op_strcmp(c, "Hello") == 0 ||
op_strcmp(c, "Hi") == 0 ||
op_strcmp(c, "Hej") == 0 ||
op_strcmp(c, "Hejsan") == 0);
}
}
A table defines a table of values with types, that can be used as input to iterate. Iterate takes a table and iterates over all of the items in the list. As you can see from the output, all values in the table are used. We verify that the values in the table is inside the table in the test. If the test fails (which it didn't), we would exit the test immediately, without doing any more iterations.
========================================================================= Opera Testsuite ========================================================================= ========================================================================= E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial10.ot(2): tutorial_10 ========================================================================= Iterate through a table ....................................... Testing, a = 3, b = 3, c == Hello Testing, a = 4, b = 54, c == Hi Testing, a = 5, b = 65, c == Hej Testing, a = 1, b = 100, c == Hejsan Passed ========================================================================= 1 test run, 0 tests failed, 0 tests skipped, 1 test OK =========================================================================