tests: added test for removing unit from all uses sections

git-svn-id: trunk@42857 -
This commit is contained in:
mattias 2013-09-18 12:20:29 +00:00
parent 4c52e89cc2
commit d876f35e8c
2 changed files with 49 additions and 3 deletions

View File

@ -2,6 +2,7 @@
Test with:
./runtests --format=plain --suite=TTestCTStdCodetools
./runtests --format=plain --suite=TestCTStdFindBlockStart
./runtests --format=plain --suite=TestCTRemoveUnitFromAllUsesSections
}
unit TestStdCodetools;
@ -22,6 +23,7 @@ type
function GetCTMarker(Code: TCodeBuffer; Comment: string; out Position: TPoint): boolean;
published
procedure TestCTStdFindBlockStart;
procedure TestCTRemoveUnitFromAllUsesSections;
end;
implementation
@ -96,8 +98,6 @@ var
begin
Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas');
// scan source
Code.Source:=GetSource();
Test('begin,try,finally,end|end','begin1','begin1end');
@ -105,6 +105,52 @@ begin
Test('begin,try,finally,|end,end','try1','try1finally');
end;
procedure TTestCTStdCodetools.TestCTRemoveUnitFromAllUsesSections;
function GetSource(UsesSrc: string): string;
begin
Result:='program TestStdCodeTools;'+LineEnding
+UsesSrc
end;
procedure Test(RemoveUnit, UsesSrc, ExpectedUsesSrc: string);
var
Header: String;
Footer: String;
Code: TCodeBuffer;
Src: String;
begin
Header:='program TestStdCodeTools;'+LineEnding;
Footer:=LineEnding
+'begin'+LineEnding
+'end.'+LineEnding;
Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas');
Code.Source:=Header+UsesSrc+Footer;
if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,RemoveUnit) then
begin
AssertEquals('RemoveUnitFromAllUsesSections failed: '+CodeToolBoss.ErrorMessage,true,false);
end else begin
Src:=Code.Source;
AssertEquals('RemoveUnitFromAllUsesSections altered header: ',Header,LeftStr(Src,length(Header)));
System.Delete(Src,1,length(Header));
AssertEquals('RemoveUnitFromAllUsesSections altered footer: ',Footer,RightStr(Src,length(Footer)));
System.Delete(Src,length(Src)-length(Footer)+1,length(Footer));
AssertEquals('RemoveUnitFromAllUsesSections: ',ExpectedUsesSrc,Src);
end;
end;
begin
Test('shellapi',
'uses'+LineEnding
+' Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,'+LineEnding
+' Dialogs, shellAPI, StdCtrls, ExtCtrls, ComCtrls, strutils, Buttons, inifiles;'+LineEnding
,
'uses'+LineEnding
+' Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,'+LineEnding
+' Dialogs, StdCtrls, ExtCtrls, ComCtrls, strutils, Buttons, inifiles;'+LineEnding
);
end;
initialization
AddToCodetoolsTestSuite(TTestCTStdCodetools);

View File

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>