Skip to content

Commit 4544505

Browse files
Partoufclaude
andcommitted
Test directives that come before the unit keyword
AST.DirectiveBeforeUnit parses a unit that starts with {$WARN ...} and {$D+} and checks that both end up first under the ntUnit root, in source order, and that the rest of the unit still parses. It fails on main and passes with the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54a0fd2 commit 4544505

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎Test/UnitTests/DelphiAST.Tests.pas‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ procedure TestUnicodeStringTypecast;
317317
end;
318318
end;
319319

320+
procedure TestDirectiveBeforeUnit;
321+
var
322+
Root: TSyntaxNode;
323+
begin
324+
Root := ParseSource('{$WARN UNIT_PLATFORM OFF}' + sLineBreak + '{$D+}' + sLineBreak +
325+
'unit Example; interface implementation end.');
326+
try
327+
AssertNotNil(Root, 'Missing root');
328+
AssertTrue(Root.Typ = ntUnit, 'The root is the unit.');
329+
AssertTrue(Root.ChildNodes[0].Typ = ntCompilerDirective, 'First directive under the root.');
330+
AssertEquals('WARN', Root.ChildNodes[0].GetAttribute(anType), 'First directive, in source order.');
331+
AssertEquals(1, Root.ChildNodes[0].Line, 'First directive line.');
332+
AssertTrue(Root.ChildNodes[1].Typ = ntCompilerDirective, 'Second directive under the root.');
333+
AssertEquals('D', Root.ChildNodes[1].GetAttribute(anType), 'Second directive, in source order.');
334+
AssertNotNil(FindDescendant(Root, ntImplementation), 'The rest of the unit still parses.');
335+
finally
336+
Root.Free;
337+
end;
338+
end;
339+
320340
procedure TestInvalidSyntax;
321341
var
322342
Root: TSyntaxNode;
@@ -397,6 +417,7 @@ procedure RunAllTests;
397417
RunTest('Node.AttributeRemove', TestAttributeRemove);
398418
RunTest('AST.RepeatedCallingConvention', TestRepeatedCallingConvention);
399419
RunTest('AST.UnicodeStringTypecast', TestUnicodeStringTypecast);
420+
RunTest('AST.DirectiveBeforeUnit', TestDirectiveBeforeUnit);
400421
RunTest('Parser.InvalidSyntax', TestInvalidSyntax);
401422
RunTest('Parser.UnexpectedEndOfFilePosition', TestUnexpectedEndOfFilePosition);
402423
{$IFNDEF FPC}

0 commit comments

Comments
 (0)