Skip to content

Commit 710dc24

Browse files
Partoufclaude
andcommitted
Test that a UnicodeString typecast has a type callee
AST.UnicodeStringTypecast parses `s := UnicodeString(p^)` and checks that the CALL's callee is an ntType named UnicodeString. It fails without the Func158 registration ("A UnicodeString typecast has a type as its callee.") and passes with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 64e3db3 commit 710dc24

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎Test/UnitTests/DelphiAST.Tests.pas‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ procedure TestRepeatedCallingConvention;
300300
end;
301301
end;
302302

303+
procedure TestUnicodeStringTypecast;
304+
var
305+
Root, CallNode, Callee: TSyntaxNode;
306+
begin
307+
Root := ParseSource('unit Example; interface implementation ' +
308+
'procedure Run(p: Pointer); var s: UnicodeString; begin s := UnicodeString(p^); end; end.');
309+
try
310+
CallNode := FindDescendant(Root, ntCall);
311+
AssertNotNil(CallNode, 'Missing call');
312+
Callee := CallNode.ChildNodes[0];
313+
AssertTrue(Callee.Typ = ntType, 'A UnicodeString typecast has a type as its callee.');
314+
AssertEquals('UnicodeString', Callee.GetAttribute(anName), 'Typecast type name.');
315+
finally
316+
Root.Free;
317+
end;
318+
end;
319+
303320
procedure TestInvalidSyntax;
304321
var
305322
Root: TSyntaxNode;
@@ -379,6 +396,7 @@ procedure RunAllTests;
379396
RunTest('Node.AttributeOverwrite', TestAttributeOverwrite);
380397
RunTest('Node.AttributeRemove', TestAttributeRemove);
381398
RunTest('AST.RepeatedCallingConvention', TestRepeatedCallingConvention);
399+
RunTest('AST.UnicodeStringTypecast', TestUnicodeStringTypecast);
382400
RunTest('Parser.InvalidSyntax', TestInvalidSyntax);
383401
RunTest('Parser.UnexpectedEndOfFilePosition', TestUnexpectedEndOfFilePosition);
384402
{$IFNDEF FPC}

0 commit comments

Comments
 (0)