codetools: test ampersand array

This commit is contained in:
mattias 2024-09-03 14:06:16 +02:00
parent daa9653962
commit 066e82b25d

View File

@ -151,6 +151,7 @@ type
procedure TestFindDeclaration_ProcRef; procedure TestFindDeclaration_ProcRef;
procedure TestFindDeclaration_Ampersand; procedure TestFindDeclaration_Ampersand;
procedure TestFindDeclaration_Ampersand_UnitName; procedure TestFindDeclaration_Ampersand_UnitName;
procedure TestFindDeclaration_AmpersandArray;
// unit/include search // unit/include search
procedure TestFindDeclaration_UnitSearch_CurrentDir; procedure TestFindDeclaration_UnitSearch_CurrentDir;
@ -299,8 +300,8 @@ var
FoundNode: TCodeTreeNode; FoundNode: TCodeTreeNode;
NameStartPos, i, j, l, IdentifierStartPos, IdentifierEndPos, NameStartPos, i, j, l, IdentifierStartPos, IdentifierEndPos,
BlockTopLine, BlockBottomLine, CommentEnd, StartOffs, TestLoop: Integer; BlockTopLine, BlockBottomLine, CommentEnd, StartOffs, TestLoop: Integer;
Marker, ExpectedType, NewType, ExpexctedCompletion, ExpexctedTerm, Marker, ExpectedType, NewType, ExpectedCompletion, ExpexctedTerm,
ExpexctedCompletionPart, ExpexctedTermPart, s: String; ExpectedCompletionPart, ExpexctedTermPart, s: String;
IdentItem: TIdentifierListItem; IdentItem: TIdentifierListItem;
ItsAKeyword, IsSubIdentifier, ExpInvert, ExpComment: boolean; ItsAKeyword, IsSubIdentifier, ExpInvert, ExpComment: boolean;
ExistingDefinition: TFindContext; ExistingDefinition: TFindContext;
@ -451,14 +452,14 @@ begin
// test identifier completion // test identifier completion
if (ExpectedPath<>'') and (Marker<>'declaration!') then begin if (ExpectedPath<>'') and (Marker<>'declaration!') then begin
for ExpexctedCompletionPart in ExpectedPath.Split(';') do begin for ExpectedCompletionPart in ExpectedPath.Split(';') do begin
ExpexctedCompletion := ExpexctedCompletionPart; ExpectedCompletion := ExpectedCompletionPart;
StartOffs := 0; StartOffs := 0;
if (ExpexctedCompletion <> '') and (ExpexctedCompletion[1] in ['+','-']) then begin if (ExpectedCompletion <> '') and (ExpectedCompletion[1] in ['+','-']) then begin
i := Pos('=', ExpexctedCompletion); i := Pos('=', ExpectedCompletion);
if i > 1 then begin if i > 1 then begin
StartOffs := StrToIntDef(copy(ExpexctedCompletion, 1, i-1), 0); StartOffs := StrToIntDef(copy(ExpectedCompletion, 1, i-1), 0);
Delete(ExpexctedCompletion, 1, i); Delete(ExpectedCompletion, 1, i);
end end
else else
StartOffs := 0; StartOffs := 0;
@ -468,13 +469,13 @@ begin
if not CodeToolBoss.GatherIdentifiers(CursorPos.Code,CursorPos.X,CursorPos.Y) if not CodeToolBoss.GatherIdentifiers(CursorPos.Code,CursorPos.X,CursorPos.Y)
then begin then begin
if ExpexctedCompletion<>'' then begin if ExpectedCompletion<>'' then begin
WriteSource(StartOffs,MainTool); WriteSource(StartOffs,MainTool);
AssertEquals('GatherIdentifiers (Loop: '+IntToStr(TestLoop)+') failed at '+MainTool.CleanPosToStr(StartOffs,true)+': '+CodeToolBoss.ErrorMessage,false,true); AssertEquals('GatherIdentifiers (Loop: '+IntToStr(TestLoop)+') failed at '+MainTool.CleanPosToStr(StartOffs,true)+': '+CodeToolBoss.ErrorMessage,false,true);
end; end;
continue; continue;
end else begin end else begin
for ExpexctedTermPart in ExpexctedCompletion.Split(',') do begin for ExpexctedTermPart in ExpectedCompletion.Split(',') do begin
ExpexctedTerm := ExpexctedTermPart; ExpexctedTerm := ExpexctedTermPart;
ExpInvert := (ExpexctedTerm <> '') and (ExpexctedTerm[1] = '!'); ExpInvert := (ExpexctedTerm <> '') and (ExpexctedTerm[1] = '!');
if ExpInvert then if ExpInvert then
@ -1384,6 +1385,30 @@ begin
FindDeclarations(Code); FindDeclarations(Code);
end; end;
procedure TTestFindDeclaration.TestFindDeclaration_AmpersandArray;
begin
StartProgram;
Add([
'type',
' TFoo = record',
' abc: integer;',
' &array:',
' record',
' x:integer;',
' end',
' end;',
'var',
' AnFoo: TFoo;',
' &array: TFoo{declaration:TFoo};',
'begin',
' AnFoo.abc{declaration:TFoo.abc} :=2;',
' AnFoo.&array{declaration:TFoo.array}.x{declaration:TFoo.array.x} := 3;',
' &Array{declaration:array}.abc{declaration:TFoo.abc} :=4;',
' &Array.&array{declaration:TFoo.array}.x{declaration:TFoo.array.x} := 5;',
'end.']);
FindDeclarations(Code);
end;
procedure TTestFindDeclaration.TestFindDeclaration_UnitSearch_CurrentDir; procedure TTestFindDeclaration.TestFindDeclaration_UnitSearch_CurrentDir;
var var
Unit1A, Unit1B: TCodeBuffer; Unit1A, Unit1B: TCodeBuffer;