Changeset 91 for trunk/UTest.pas
- Timestamp:
- Feb 2, 2022, 4:33:25 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTest.pas
r90 r91 14 14 15 15 TTestCase = class 16 public 16 17 Name: string; 17 18 Result: TTestResult; 18 procedure Run; 19 Log: string; 20 procedure Run; virtual; 19 21 end; 22 23 TTestCaseClass = class of TTestCase; 20 24 21 25 { TTestCases } 22 26 23 27 TTestCases = class(TFPGObjectList<TTestCase>) 24 function AddNew(Name: string ): TTestCase;28 function AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 25 29 end; 26 30 31 { TTestCaseLoadSave } 32 33 TTestCaseLoadSave = class(TTestCase) 34 Input: string; 35 Output: string; 36 procedure Run; override; 37 procedure Evaluate(Passed: Boolean); 38 end; 39 40 const 41 ResultText: array[TTestResult] of string = ('None', 'Passed', 'Failed'); 42 43 27 44 implementation 45 46 uses 47 UContact; 48 49 { TTestCaseLoadSave } 50 51 procedure TTestCaseLoadSave.Run; 52 var 53 Lines: TStringList; 54 begin 55 Lines := TStringList.Create; 56 try 57 with TContactsFile.Create do 58 try 59 Lines.Text := Input; 60 LoadFromStrings(Lines); 61 Lines.Text := ''; 62 SaveToStrings(Lines); 63 Evaluate(Lines.Text = Output); 64 if Result <> trPassed then begin 65 Log := 'Expected:' + LineEnding + 66 '"' + Output + '"' + LineEnding + LineEnding + 67 'Output:' + LineEnding + 68 '"' + Lines.Text + '"'; 69 end; 70 finally 71 Free; 72 end; 73 finally 74 Lines.Free; 75 end; 76 end; 77 78 procedure TTestCaseLoadSave.Evaluate(Passed: Boolean); 79 begin 80 if Passed then Result := trPassed 81 else Result := trFailed; 82 end; 28 83 29 84 { TTestCase } … … 36 91 { TTestCases } 37 92 38 function TTestCases.AddNew(Name: string ): TTestCase;93 function TTestCases.AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 39 94 begin 40 Result := T TestCase.Create;95 Result := TestClass.Create; 41 96 Result.Name := Name; 42 97 Add(Result);
Note:
See TracChangeset
for help on using the changeset viewer.