codetools: tests: added objccategory

git-svn-id: trunk@49660 -
This commit is contained in:
mattias 2015-08-13 07:01:05 +00:00
parent be9ce3be19
commit 2c559c3ecb
5 changed files with 83 additions and 6 deletions

1
.gitattributes vendored
View File

@ -986,6 +986,7 @@ components/codetools/stdcodetools.pas svneol=native#text/pascal
components/codetools/tests/fdt_basic.pas svneol=native#text/plain components/codetools/tests/fdt_basic.pas svneol=native#text/plain
components/codetools/tests/fdt_classhelper.pas svneol=native#text/plain components/codetools/tests/fdt_classhelper.pas svneol=native#text/plain
components/codetools/tests/fdt_nestedclasses.pas svneol=native#text/plain components/codetools/tests/fdt_nestedclasses.pas svneol=native#text/plain
components/codetools/tests/fdt_objccategory.pas svneol=native#text/plain
components/codetools/tests/fdtbase.pas svneol=native#text/plain components/codetools/tests/fdtbase.pas svneol=native#text/plain
components/codetools/tests/finddeclarationtest.lpi svneol=native#text/plain components/codetools/tests/finddeclarationtest.lpi svneol=native#text/plain
components/codetools/tests/finddeclarationtest.lpr svneol=native#text/plain components/codetools/tests/finddeclarationtest.lpr svneol=native#text/plain

View File

@ -0,0 +1,57 @@
unit fdt_objccategory;
{$mode objfpc}{$H+}
{$ModeSwitch objectivec1}
interface
uses
Classes, SysUtils;
type
{ ta }
ta = objcclass(NSObject)
end;
{ ca }
ca = objccategory(NSObject)
procedure categoryAmethod; message 'categoryAmethod';
end;
{ cb }
cb = objccategory(ta)
procedure categoryBmethod; message 'categoryBmethod';
end;
procedure DoIt;
implementation
{ ca }
procedure ca.categoryAmethod;
begin
end;
{ cb }
procedure cb.categoryBmethod;
begin
end;
procedure DoIt;
var
a: NSObject;
begin
a:=ta(ta.alloc).init;
a.categoryAmethod{declaration:fdt_objccategory.ca.categoryAmethod};
end;
end.

View File

@ -4,11 +4,14 @@
./finddeclarationtest --format=plain --suite=TestFindDeclaration_Base ./finddeclarationtest --format=plain --suite=TestFindDeclaration_Base
./finddeclarationtest --format=plain --suite=TestFindDeclaration_NestedClasses ./finddeclarationtest --format=plain --suite=TestFindDeclaration_NestedClasses
./finddeclarationtest --format=plain --suite=TestFindDeclaration_ClassHelper ./finddeclarationtest --format=plain --suite=TestFindDeclaration_ClassHelper
./finddeclarationtest --format=plain --suite=TestFindDeclaration_ObjCCategory
} }
unit fdtbase; unit fdtbase;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{off $define VerboseFindDeclarationTests}
interface interface
uses uses
@ -27,6 +30,7 @@ type
procedure TestFindDeclaration_Base; procedure TestFindDeclaration_Base;
procedure TestFindDeclaration_NestedClasses; procedure TestFindDeclaration_NestedClasses;
procedure TestFindDeclaration_ClassHelper; procedure TestFindDeclaration_ClassHelper;
procedure TestFindDeclaration_ObjCCategory;
end; end;
var var
@ -76,6 +80,9 @@ var
Marker: String; Marker: String;
begin begin
Filename:=TrimAndExpandFilename(Filename); Filename:=TrimAndExpandFilename(Filename);
{$IFDEF VerboseFindDeclarationTests}
debugln(['TTestFindDeclaration.FindDeclarations File=',Filename]);
{$ENDIF}
Code:=CodeToolBoss.LoadFile(Filename,true,false); Code:=CodeToolBoss.LoadFile(Filename,true,false);
if Code=nil then if Code=nil then
raise Exception.Create('unable to load '+Filename); raise Exception.Create('unable to load '+Filename);
@ -106,11 +113,15 @@ begin
if Marker='declaration' then begin if Marker='declaration' then begin
ExpectedPath:=copy(Src,PathPos,CommentP-1-PathPos); ExpectedPath:=copy(Src,PathPos,CommentP-1-PathPos);
//debugln(['TTestFindDeclaration.FindDeclarations ExpectedPath=',ExpectedPath]); //debugln(['TTestFindDeclaration.FindDeclarations ExpectedPath=',ExpectedPath]);
{ $IFDEF VerboseFindDeclarationTests}
debugln(['TTestFindDeclaration.FindDeclarations searching "',Marker,'" at ',Tool.CleanPosToStr(NameStartPos-1),' ExpectedPath=',ExpectedPath]);
{ $ENDIF}
Tool.CleanPosToCaret(NameStartPos-1,CursorPos); Tool.CleanPosToCaret(NameStartPos-1,CursorPos);
if not CodeToolBoss.FindDeclaration(CursorPos.Code,CursorPos.X,CursorPos.Y, if not CodeToolBoss.FindDeclaration(CursorPos.Code,CursorPos.X,CursorPos.Y,
FoundCursorPos.Code,FoundCursorPos.X,FoundCursorPos.Y,FoundTopLine) FoundCursorPos.Code,FoundCursorPos.X,FoundCursorPos.Y,FoundTopLine)
then begin then begin
AssertEquals('find declaration failed at '+Tool.CleanPosToStr(NameStartPos-1)+': '+CodeToolBoss.ErrorMessage,false,true); if ExpectedPath<>'' then
AssertEquals('find declaration failed at '+Tool.CleanPosToStr(NameStartPos-1)+': '+CodeToolBoss.ErrorMessage,false,true);
continue; continue;
end else begin end else begin
FoundTool:=CodeToolBoss.GetCodeToolForSource(FoundCursorPos.Code,true,true) as TFindDeclarationTool; FoundTool:=CodeToolBoss.GetCodeToolForSource(FoundCursorPos.Code,true,true) as TFindDeclarationTool;
@ -158,6 +169,11 @@ begin
FindDeclarations('fdt_classhelper.pas'); FindDeclarations('fdt_classhelper.pas');
end; end;
procedure TTestFindDeclaration.TestFindDeclaration_ObjCCategory;
begin
FindDeclarations('fdt_objccategory.pas');
end;
initialization initialization
GetTestRegistry.TestName := 'All tests'; GetTestRegistry.TestName := 'All tests';
BugsTestSuite := TTestSuite.Create('Bugs'); BugsTestSuite := TTestSuite.Create('Bugs');

View File

@ -41,7 +41,7 @@
<PackageName Value="fpcunitconsolerunner"/> <PackageName Value="fpcunitconsolerunner"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="5"> <Units Count="6">
<Unit0> <Unit0>
<Filename Value="finddeclarationtest.lpr"/> <Filename Value="finddeclarationtest.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -49,23 +49,23 @@
<Unit1> <Unit1>
<Filename Value="fdtbase.pas"/> <Filename Value="fdtbase.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fdtbase"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="fdt_classhelper.pas"/> <Filename Value="fdt_classhelper.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fdt_classhelper"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="fdt_nestedclasses.pas"/> <Filename Value="fdt_nestedclasses.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fdt_nestedclasses"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="fdt_basic.pas"/> <Filename Value="fdt_basic.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fdt_basic"/>
</Unit4> </Unit4>
<Unit5>
<Filename Value="fdt_objccategory.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -22,6 +22,9 @@ program finddeclarationtest;
uses uses
Classes, sysutils, consoletestrunner, dom, fpcunit, CodeToolManager, Classes, sysutils, consoletestrunner, dom, fpcunit, CodeToolManager,
CodeToolsConfig, LazLogger, fdtbase, fdt_classhelper, fdt_nestedclasses, CodeToolsConfig, LazLogger, fdtbase, fdt_classhelper, fdt_nestedclasses,
{$IFDEF Darwin}
fdt_objccategory,
{$ENDIF}
fdt_basic; fdt_basic;
const const