In the following example, this technique will be adopted in just the first steps and with a certain degree
of freedom to not bore to the reader. It will be implemented in the base for a simple validation
framework. What is needed is a very simple object that performs a validation and returns true if the
validation is OK or false if it is not; in the latter case an error message will be produced.
So let us start with the first test case class. TestERegValidator extends TestCase . Usually the test case
classes are named after the class name that they pretend to test. The first validation class will accept a
text value and a regular expression pattern to perform the validation.
class TestERegValidator extends haxe.unit.TestCase
{
public function testValidateFalse()
{
var v = new ERegValidator(???test???, ???x???, null);
assertFalse(v.validate());
}
}
Remember that regular expressions are not present in Flash prior to version 9.
In the test an instance of the class ERegValidator is instantiated. The first test will check that a string
value test does not match the pattern x; this is expressed using the assertFalse function that will fail if
the passed argument is true .
Pages:
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347