Prev | Current Page 338 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

validate());
}
This time the tests run two and one of them fails. It is time to accommodate the code so that both the
tests validated may pass.
class ERegValidator
{
private var value : String;
private var pattern : String;
private var opt : String;
public function new(value : String, pattern : String, ?opt : String)
{
this.value = value;
this.pattern = pattern;
this.opt = if(opt == null) ?????? else opt;
}
public function validate() : Bool
{
var er = new EReg(pattern, opt);
return er.match(value);
}
}
The constructor parameters are now maintained in the instance and effectively used for the validation.
Now, in case of failure, an error must be available to inform the user that some problems prevent the
validation process to be successfully completed. A new test is added:
public function testEmptyError()
{
var v = new ERegValidator(???test???, ???t???);
v.validate();
assertEquals(v.error, null);
}
A new variable error is required in the class and in the case of successful validation, it must have a
null value.


Pages:
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350