View Issue Details

IDProjectCategoryView StatusLast Update
0037808FPCPackagespublic2020-09-24 12:10
ReporterJoe care Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86-64OSWin64 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037808: [fcl-passrc][patch] tests/tcscanner fail: LineEndings in comments are always converted to #10
Descriptionin Iests/tcScanner (TTestScanner.TestComment5) the expected result of the LineEnding is LineEnding, but gives 0000010 even on Windows-Systems.
Steps To ReproduceRun tcScanner on a Win-System, should also fail on Systems with only 0000013 as LineEnding.
Additional InformationSo either the test is wrong and the scanner is supposed to convert the LineEnding to 0000010 or the test is correct and the scanner has to be changed.
the patch goes for the second and also provides more Comment-Tests.
Tagsfcl-passrc, LineEnding, patch, test
Fixed in Revision46941
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Joe care

2020-09-24 11:25

reporter  

LIneending_in_comments.patch (4,012 bytes)   
Index: src/pscanner.pp
===================================================================
--- src/pscanner.pp	(Revision 46934)
+++ src/pscanner.pp	(Arbeitskopie)
@@ -4194,6 +4194,7 @@
   SectionLength, NestingLevel, Index: Integer;
   {$ifdef UsePChar}
   OldLength: integer;
+  Ch: Char;
   {$else}
   s: string;
   l: integer;
@@ -4341,13 +4347,19 @@
             begin
             SectionLength:=FTokenPos - TokenStart;
             {$ifdef UsePChar}
-            SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for #10
+            SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
             if SectionLength > 0 then
-              Move(TokenStart^, FCurTokenString[OldLength + 1], SectionLength);
-            Inc(OldLength, SectionLength+1);
-            FCurTokenString[OldLength] := #10;
+              Move(TokenStart^, FCurTokenString[OldLength + 1],SectionLength);
+
+            // Corrected JC: Append the correct lineending
+            Inc(OldLength, SectionLength);
+            for Ch in LineEnding do
+              begin
+                Inc(OldLength);
+                FCurTokenString[OldLength] := Ch;
+              end;
             {$else}
-            FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
+            FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
             {$endif}
             if not FetchLocalLine then
               begin
@@ -4646,13 +4663,19 @@
           begin
           SectionLength := FTokenPos - TokenStart;
           {$ifdef UsePChar}
-          SetLength(FCurTokenString, OldLength + SectionLength+1); // +1 for the #10
+          SetLength(FCurTokenString, OldLength + SectionLength + length(LineEnding)); // Corrected JC
           if SectionLength > 0 then
             Move(TokenStart^, FCurTokenString[OldLength + 1],SectionLength);
-          Inc(OldLength, SectionLength+1);
-          FCurTokenString[OldLength] := #10;
+
+          // Corrected JC: Append the correct lineending
+          Inc(OldLength, SectionLength);
+          for Ch in LineEnding do
+            begin
+              Inc(OldLength);
+              FCurTokenString[OldLength] := Ch;
+            end;
           {$else}
-          FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+#10;
+          FCurTokenString:=FCurTokenString+copy(FCurLine,TokenStart,SectionLength)+LineEnding; // Corrected JC
           {$endif}
           if not FetchLocalLine then
           begin
Index: tests/tcscanner.pas
===================================================================
--- tests/tcscanner.pas	(Revision 46934)
+++ tests/tcscanner.pas	(Arbeitskopie)
@@ -80,6 +80,10 @@
     procedure TestComment3;
     procedure TestComment4;
     procedure TestComment5;
+    procedure TestComment6;
+    procedure TestComment7;
+    procedure TestComment8;
+    procedure TestComment9;
     procedure TestNestedComment1;
     procedure TestNestedComment2;
     procedure TestNestedComment3;
@@ -564,6 +570,34 @@
   AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
 end;
 
+procedure TTestScanner.TestComment6;
+
+begin
+  DoTestToken(tkComment,'{ abc }',False);
+  AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
+end;
+
+procedure TTestScanner.TestComment7;
+
+begin
+  DoTestToken(tkComment,'{ abc'+LineEnding+'def }',False);
+  AssertEquals('Correct comment',' abc'+LineEnding+'def ',Scanner.CurTokenString);
+end;
+
+procedure TTestScanner.TestComment8;
+
+begin
+  DoTestToken(tkComment,'// abc ',False);
+  AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
+end;
+
+procedure TTestScanner.TestComment9;
+
+begin
+  DoTestToken(tkComment,'// abc '+LineEnding,False);
+  AssertEquals('Correct comment',' abc ',Scanner.CurTokenString);
+end;
+
 procedure TTestScanner.TestNestedComment1;
 begin
   TestToken(tkComment,'// { comment } ');
 
 
LIneending_in_comments.patch (4,012 bytes)   

Michael Van Canneyt

2020-09-24 12:10

administrator   ~0125816

Fixed, but had to change your patch:
"for C in LineEnding" does not work on platforms where LineEnding is a character, you get a compiler error.

Issue History

Date Modified Username Field Change
2020-09-24 11:25 Joe care New Issue
2020-09-24 11:25 Joe care File Added: LIneending_in_comments.patch
2020-09-24 11:26 Joe care Tag Attached: fcl-passrc
2020-09-24 11:26 Joe care Tag Attached: patch
2020-09-24 11:26 Joe care Tag Attached: test
2020-09-24 11:26 Joe care Tag Attached: LineEnding
2020-09-24 12:10 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-09-24 12:10 Michael Van Canneyt Status new => resolved
2020-09-24 12:10 Michael Van Canneyt Resolution open => fixed
2020-09-24 12:10 Michael Van Canneyt Fixed in Version => 3.3.1
2020-09-24 12:10 Michael Van Canneyt Fixed in Revision => 46941
2020-09-24 12:10 Michael Van Canneyt FPCTarget => 3.2.2
2020-09-24 12:10 Michael Van Canneyt Note Added: 0125816