From 3cd01247f7a4d210defafa0e005f217c86cf2431 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 12 Dec 2018 09:47:47 +0000 Subject: [PATCH] codetools: test anonym procs args and find declaration git-svn-id: trunk@59798 - --- .../codetools/tests/testfinddeclaration.pas | 36 ++++++++++++++++++- .../codetools/tests/testpascalparser.pas | 4 +-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/components/codetools/tests/testfinddeclaration.pas b/components/codetools/tests/testfinddeclaration.pas index d0f2b1463d..d967b14ef6 100644 --- a/components/codetools/tests/testfinddeclaration.pas +++ b/components/codetools/tests/testfinddeclaration.pas @@ -101,6 +101,7 @@ type procedure TestFindDeclaration_GuessType; procedure TestFindDeclaration_Attributes; procedure TestFindDeclaration_BracketOpen; + procedure TestFindDeclaration_AnonymProc_Assign; // test all files in directories: procedure TestFindDeclaration_FPCTests; procedure TestFindDeclaration_LazTests; @@ -177,6 +178,8 @@ procedure TCustomTestFindDeclaration.FindDeclarations(aCode: TCodeBuffer); end; function NodeAsPath(Tool: TFindDeclarationTool; Node: TCodeTreeNode): string; + var + aName: String; begin Result:=''; while Node<>nil do begin @@ -188,7 +191,12 @@ procedure TCustomTestFindDeclaration.FindDeclarations(aCode: TCodeBuffer); ctnInterface,ctnUnit: PrependPath(Tool.GetSourceName(false),Result); ctnProcedure: - PrependPath(Tool.ExtractProcName(Node,[]),Result); + begin + aName:=Tool.ExtractProcName(Node,[]); + if aName='' then + aName:='$ano'; + PrependPath(aName,Result); + end; ctnProperty: PrependPath(Tool.ExtractPropName(Node,false),Result); ctnUseUnit: @@ -925,6 +933,32 @@ begin FindDeclarations(Code); end; +procedure TTestFindDeclaration.TestFindDeclaration_AnonymProc_Assign; +begin + StartProgram; + Add([ + '{$mode objfpc}{$modeswitch closures}', + 'type', + ' int = word;', + ' TFunc = function(i: int): int;', + 'var f: TFunc;', + 'procedure DoIt(a: int);', + ' procedure Sub(b: int);', + ' begin', + ' f:=function(c: int): int', + ' begin', + ' f{declaration:f}:=nil;', + ' a{declaration:doit.a}:=b{declaration:doit.sub.b}+c{declaration:doit.sub.$ano.c};', + ' end;', + ' end;', + 'begin', + 'end;', + 'begin', + 'end.', + '']); + FindDeclarations(Code); +end; + procedure TTestFindDeclaration.TestFindDeclaration_FPCTests; begin TestFiles('fpctests'); diff --git a/components/codetools/tests/testpascalparser.pas b/components/codetools/tests/testpascalparser.pas index 3f14c2ef2a..c19ccccf88 100644 --- a/components/codetools/tests/testpascalparser.pas +++ b/components/codetools/tests/testpascalparser.pas @@ -51,7 +51,7 @@ type procedure TestParseExternalConst; procedure TestParseModeTP; procedure TestParseProcAnoAssign; - procedure TestParseProcAnoArg; // ToDo + procedure TestParseProcAnoArg; end; implementation @@ -502,9 +502,9 @@ end; procedure TTestPascalParser.TestParseProcAnoArg; begin - exit; Add([ 'program test1;', + '{$mode objfpc}', '{$modeswitch closures}', 'procedure DoIt;', 'begin',