Commits

Shinya Okano committed a685279

impl: AssertIsNil, AssertIsNotNil

Comments (0)

Files changed (2)

Example/MyUnit2Test.pas

     procedure SetUp; override;
     procedure TearDown; override;
     procedure TestGetName;
+    procedure TestIsNil;
   end;
 
 implementation
   AssertEquals(FPerson.GetName, 'Foo');
 end;
 
+procedure TMyUnit2Test.TestIsNil;
+begin
+  AssertIsNil(nil);
+end;
+
 initialization
   RegisterTest(TMyUnit2Test);
 

Nullpobug.UnitTest.pas

     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>);
     property OnRanTestMethod: TOnRanTestMethod read FOnRanTestMethod write FOnRanTestMethod;
   end;
     raise EAssertionError.CreateFmt('%s != %s', [Value1, Value2]);
 end;
 
+procedure TTestCase.AssertIsNil(Value: TObject);
+begin
+  if not (Value = nil) then
+    raise EAssertionError.CreateFmt('%s is not nil.', [Value.ToString]);
+end;
+
+procedure TTestCase.AssertIsNotNil(Value: TObject);
+begin
+  if Value = nil then
+    raise EAssertionError.CreateFmt('%s is nil.', [Value.ToString]);
+end;
+
 procedure TTestCase.Run(TestResultList: TObjectList<TTestResult>);
 var
   RttiContext: TRttiContext;