Browse Source

* Handle case where there is no end-of-document

Michaël Van Canneyt 7 months ago
parent
commit
e9eb8297bc

+ 1 - 1
packages/fcl-yaml/src/fpyaml.parser.pp

@@ -437,7 +437,7 @@ begin
       ConsumeToken;
       ConsumeToken;
       lToken:=Peek;
       lToken:=Peek;
       end;
       end;
-    While not (lToken.token in [ytEOF,ytDocumentEnd]) do
+    While not (lToken.token in [ytEOF,ytDocumentStart,ytDocumentEnd]) do
       begin
       begin
       case lToken.Token of
       case lToken.Token of
         ytAnchor : ParseAnchor;
         ytAnchor : ParseAnchor;

+ 6 - 10
packages/fcl-yaml/test/testyaml.lpi

@@ -24,11 +24,6 @@
     <RunParams>
     <RunParams>
       <FormatVersion Value="2"/>
       <FormatVersion Value="2"/>
     </RunParams>
     </RunParams>
-    <RequiredPackages>
-      <Item>
-        <PackageName Value="FCL"/>
-      </Item>
-    </RequiredPackages>
     <Units>
     <Units>
       <Unit>
       <Unit>
         <Filename Value="testyaml.lpr"/>
         <Filename Value="testyaml.lpr"/>
@@ -38,10 +33,6 @@
         <Filename Value="utyamlparser.pp"/>
         <Filename Value="utyamlparser.pp"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
       </Unit>
       </Unit>
-      <Unit>
-        <Filename Value="../src/fpyaml.data.pas"/>
-        <IsPartOfProject Value="True"/>
-      </Unit>
       <Unit>
       <Unit>
         <Filename Value="../src/fpyaml.scanner.pp"/>
         <Filename Value="../src/fpyaml.scanner.pp"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
@@ -70,6 +61,10 @@
         <Filename Value="../src/fpyaml.strings.pp"/>
         <Filename Value="../src/fpyaml.strings.pp"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
       </Unit>
       </Unit>
+      <Unit>
+        <Filename Value="../src/fpyaml.data.pp"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
     </Units>
     </Units>
   </ProjectOptions>
   </ProjectOptions>
   <CompilerOptions>
   <CompilerOptions>
@@ -79,11 +74,12 @@
     </Target>
     </Target>
     <SearchPaths>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
       <IncludeFiles Value="$(ProjOutDir)"/>
-      <OtherUnitFiles Value="src"/>
+      <OtherUnitFiles Value="src;../src"/>
       <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
       <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     </SearchPaths>
     <Linking>
     <Linking>
       <Debugging>
       <Debugging>
+        <DebugInfoType Value="dsDwarf3"/>
         <UseHeaptrc Value="True"/>
         <UseHeaptrc Value="True"/>
       </Debugging>
       </Debugging>
       <Options>
       <Options>

+ 42 - 0
packages/fcl-yaml/test/utyamlparser.pp

@@ -47,6 +47,8 @@ type
     procedure TestCreate;
     procedure TestCreate;
     procedure TestEmptyDocument;
     procedure TestEmptyDocument;
     procedure TestVersionEmptyDocument;
     procedure TestVersionEmptyDocument;
+    procedure TestMultiDocument;
+    procedure TestMultiDocumentNoEnd;
     procedure TestScalar;
     procedure TestScalar;
     procedure TestAnchoredScalar;
     procedure TestAnchoredScalar;
     procedure TestBlockSequence;
     procedure TestBlockSequence;
@@ -506,6 +508,46 @@ begin
   AssertEquals('Document empty',0,Document.Count);
   AssertEquals('Document empty',0,Document.Count);
 end;
 end;
 
 
+procedure TTestYamlParser.TestMultiDocument;
+var
+  doc : TYAMLDocument;
+begin
+  Parse(['%YAML 1.2','---','abc','...','---','def','...']);
+  AssertNotNull('Data',Data);
+  AssertEquals('YAML Stream',TYAMLStream,Data.ClassType);
+  AssertEquals('YAML Stream item count',2,YAML.Count);
+  AssertEquals('YAML Stream document count',2,YAML.DocumentCount);
+  Doc:=YAML.Documents[0];
+  AssertNotNull('Document 1',Doc);
+  AssertEquals('Document 1 Major',1,Doc.Version.Major);
+  AssertEquals('Document 1 Minor',2,Doc.Version.Minor);
+  AssertEquals('Document 1 element count',1,Doc.Count);
+  AssertScalar('Document 1 element',Doc[0],yttString,'abc');
+  Doc:=YAML.Documents[1];
+  AssertNotNull('Document 2',doc);
+  AssertEquals('Document 2 element count',1,Doc.Count);
+  AssertScalar('Document 2 element',Doc[0],yttString,'def');
+end;
+
+procedure TTestYamlParser.TestMultiDocumentNoEnd;
+var
+  doc : TYAMLDocument;
+begin
+  Parse(['abc','---','def']);
+  AssertNotNull('Data',Data);
+  AssertEquals('YAML Stream',TYAMLStream,Data.ClassType);
+  AssertEquals('YAML Stream item count',2,YAML.Count);
+  AssertEquals('YAML Stream document count',2,YAML.DocumentCount);
+  Doc:=YAML.Documents[0];
+  AssertNotNull('Document 1',Doc);
+  AssertEquals('Document 1 element count',1,Doc.Count);
+  AssertScalar('Document 1 element',Doc[0],yttString,'abc');
+  Doc:=YAML.Documents[1];
+  AssertNotNull('Document 2',doc);
+  AssertEquals('Document 2 element count',1,Doc.Count);
+  AssertScalar('Document 2 element',Doc[0],yttString,'def');
+end;
+
 function TTestYamlParser.GetDocument: TYAMLDocument;
 function TTestYamlParser.GetDocument: TYAMLDocument;
 
 
 begin
 begin