Commits

Shinya Okano committed d60819e

Changed: add assert methods

Comments (0)

Files changed (3)

Example/MyUnit1.pas

 
 function Add(A, B: Integer): Integer;
 function Sub(A, B: Integer): Integer;
+function Add64(A, B: Int64): Int64;
+function JoinString(A, B: ShortString): ShortString; overload;
+function JoinString(A, B: String): String; overload;
+function JoinString(A, B: RawByteString): RawByteString; overload;
 
 implementation
 
   Result := A - B;
 end;
 
+function Add64(A, B: Int64): Int64;
+begin
+  Result := A + B;
+end;
+
+function JoinString(A, B: ShortString): ShortString;
+begin
+  Result := A + B;
+end;
+
+function JoinString(A, B: String): String;
+begin
+  Result := A + B;
+end;
+
+function JoinString(A, B: RawByteString): RawByteString;
+begin
+  Result := A + B;
+end;
+
 end.

Example/MyUnit1Test.pas

     {$ENDIF}
     procedure TestSkip;
     procedure TestSlow;
+    procedure TestAdd64;
+    procedure TestJoinString;
   end;
 
 implementation
   Sleep(500);
 end;
 
+procedure TMyUnit1Test.TestAdd64;
+begin
+  AssertEquals(Add64(999999999999, 1), 1000000000000);
+end;
+
+procedure TMyUnit1Test.TestJoinString;
+begin
+  AssertEquals(JoinString('foo', 'bar'), 'foobar');
+end;
+
 initialization
   RegisterTest(TMyUnit1Test);
 

Nullpobug.UnitTest.pas

     destructor Destroy; override;
     procedure SetUp; virtual;
     procedure TearDown; virtual;
-    procedure AssertTrue(Value: Boolean);
-    procedure AssertFalse(Value: Boolean);
-    procedure AssertEquals(Value1, Value2: Integer); overload;
-    procedure AssertEquals(Value1, Value2: String); overload;
-    procedure AssertIsNil(Value: TObject);
-    procedure AssertIsNotNil(Value: TObject);
-    procedure Run(TestResultList: TObjectList<TTestResult>);
+    procedure Assert(Value: Boolean); virtual;
+    procedure AssertTrue(Value: Boolean); virtual;
+    procedure AssertFalse(Value: Boolean); virtual;
+    procedure AssertEquals(Value1, Value2: Integer); overload; virtual;
+    procedure AssertEquals(Value1, Value2: Cardinal); overload; virtual;
+    procedure AssertEquals(Value1, Value2: Int64); overload; virtual;
+    procedure AssertEquals(Value1, Value2: UInt64); overload; virtual;
+    procedure AssertEquals(Value1, Value2: ShortString); overload; virtual;
+    procedure AssertEquals(Value1, Value2: String); overload; virtual;
+    procedure AssertEquals(Value1, Value2: RawByteString); overload; virtual;
+    procedure AssertIsNil(Value: TObject); virtual;
+    procedure AssertIsNotNil(Value: TObject); virtual;
+    procedure Run(TestResultList: TObjectList<TTestResult>); virtual;
     property OnRanTestMethod: TOnRanTestMethod read FOnRanTestMethod write FOnRanTestMethod;
   end;
 
 begin
 end;
 
-procedure TTestCase.AssertTrue(Value: Boolean);
+procedure TTestCase.Assert(Value: Boolean);
 begin
   if not (Value = True) then
     raise EAssertionError.CreateFmt('%s != True', [BoolToStr(Value, True)]);
 end;
 
+procedure TTestCase.AssertTrue(Value: Boolean);
+begin
+  Assert(Value);
+end;
+
 procedure TTestCase.AssertFalse(Value: Boolean);
 begin
   if not (Value = False) then
     raise EAssertionError.CreateFmt('%d != %d', [Value1, Value2]);
 end;
 
+procedure TTestCase.AssertEquals(Value1, Value2: Cardinal);
+begin
+  if not (Value1 = Value2) then
+    raise EAssertionError.CreateFmt('%d != %d', [Value1, Value2]);
+end;
+
+procedure TTestCase.AssertEquals(Value1, Value2: Int64);
+begin
+  if not (Value1 = Value2) then
+    raise EAssertionError.CreateFmt('%d != %d', [Value1, Value2]);
+end;
+
+procedure TTestCase.AssertEquals(Value1, Value2: UInt64);
+begin
+  if not (Value1 = Value2) then
+    raise EAssertionError.CreateFmt('%d != %d', [Value1, Value2]);
+end;
+
+procedure TTestCase.AssertEquals(Value1, Value2: ShortString);
+begin
+  if not (Value1 = Value2) then
+    raise EAssertionError.CreateFmt('%s != %s', [Value1, Value2]);
+end;
+
 procedure TTestCase.AssertEquals(Value1, Value2: String);
 begin
   if not (Value1 = Value2) then
     raise EAssertionError.CreateFmt('%s != %s', [Value1, Value2]);
 end;
 
+procedure TTestCase.AssertEquals(Value1, Value2: RawByteString);
+begin
+  if not (Value1 = Value2) then
+    raise EAssertionError.CreateFmt('%s != %s', [Value1, Value2]);
+end;
+
 procedure TTestCase.AssertIsNil(Value: TObject);
 begin
   if not (Value = nil) then