-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegularExpressionUnitTest.pas
61 lines (43 loc) · 2.12 KB
/
RegularExpressionUnitTest.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
type
TRegularExpressionUnitTest = class(TAbstractUnitTest)
public
constructor Create;
procedure ExecuteTest; override;
destructor Destroy; override;
end;
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
constructor TRegularExpressionUnitTest.Create;
begin
inherited Create;
end;
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
procedure TRegularExpressionUnitTest.ExecuteTest;
var
RegularExpression: TPerlRegEx;
begin
RegularExpression := TPerlRegEx.Create; RegularExpression.RegEx := '^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$'; RegularExpression.Options := [preCaseLess]; RegularExpression.Compile;
RegularExpression.Subject := '2099-12-31'; if not(RegularExpression.Match) then raise FailedUnitTestException.Create;
RegularExpression.Subject := '1970-05-22'; if not(RegularExpression.Match) then raise FailedUnitTestException.Create;
RegularExpression.Subject := '2099-19-31'; if RegularExpression.Match then raise FailedUnitTestException.Create;
RegularExpression.Subject := '9999-12-31'; if RegularExpression.Match then raise FailedUnitTestException.Create;
RegularExpression.Subject := 'NO'; if RegularExpression.Match then raise FailedUnitTestException.Create;
RegularExpression.Subject := ''; if RegularExpression.Match then raise FailedUnitTestException.Create;
RegularExpression.Free;
end;
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
destructor TRegularExpressionUnitTest.Destroy;
begin
inherited Destroy;
end;
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------