summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-29 00:34:32 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-29 00:34:32 +1100
commit8e1f7f57bc08b98d95beead0630964baf913cc0d (patch)
tree00a29bf6ee0f7f804c854c380dab03e79ab4b7c9
parent6f15340717a5d2dccdcf8de0a03a161c5abeef70 (diff)
Clarified Cursor details in Packrat.Graphs, added test for Find
-rw-r--r--src/packrat-graphs.adb6
-rw-r--r--src/packrat-graphs.ads5
-rw-r--r--test/ratnest-tests.adb82
-rw-r--r--test/ratnest-tests.ads21
-rw-r--r--test/test_main.adb4
5 files changed, 113 insertions, 5 deletions
diff --git a/src/packrat-graphs.adb b/src/packrat-graphs.adb
index 1206a89..1411259 100644
--- a/src/packrat-graphs.adb
+++ b/src/packrat-graphs.adb
@@ -471,7 +471,7 @@ package body Packrat.Graphs is
begin
return Result : Reversible_Iterator do
Result.My_Container := This'Unrestricted_Access;
- Result.My_Position := No_Position;
+ Result.My_Position := Cursor (No_Position);
end return;
end Iterate;
@@ -483,7 +483,7 @@ package body Packrat.Graphs is
begin
return Result : Reversible_Iterator do
Result.My_Container := This'Unrestricted_Access;
- Result.My_Position := No_Position;
+ Result.My_Position := Cursor (No_Position);
end return;
end Iterate_Subtree;
@@ -495,7 +495,7 @@ package body Packrat.Graphs is
begin
return Result : Forward_Iterator do
Result.My_Container := This'Unrestricted_Access;
- Result.My_Position := No_Position;
+ Result.My_Position := Cursor (No_Position);
end return;
end Iterate_Choice;
diff --git a/src/packrat-graphs.ads b/src/packrat-graphs.ads
index 877be3a..0ef298e 100644
--- a/src/packrat-graphs.ads
+++ b/src/packrat-graphs.ads
@@ -33,7 +33,7 @@ package Packrat.Graphs is
- No_Position : constant Cursor;
+ No_Position : constant My_Interfaces.Cursor'Class;
Empty_Graph : constant Parse_Graph;
@@ -339,7 +339,8 @@ private
No_Node : constant Node := (My_Interfaces.Node with null record);
- No_Position : constant Cursor := (My_Interfaces.Cursor with null record);
+ No_Position_Actual : constant Cursor := (My_Interfaces.Cursor with null record);
+ No_Position : constant My_Interfaces.Cursor'Class := No_Position_Actual;
Empty_Graph : constant Parse_Graph := (My_Interfaces.Graph with null record);
diff --git a/test/ratnest-tests.adb b/test/ratnest-tests.adb
index 3d51081..5153b9f 100644
--- a/test/ratnest-tests.adb
+++ b/test/ratnest-tests.adb
@@ -6,6 +6,7 @@ with
Ada.Strings.Maps,
Ada.Exceptions,
Packrat.Lexer.Debug,
+ Packrat.Graphs,
Packrat.Util;
@@ -1240,6 +1241,87 @@ package body Ratnest.Tests is
+ package body Graphs is
+
+
+ type My_Labels is (One, Two, Three, Four, Five, Six);
+
+ package My_Interfaces is new Packrat.Interfaces (My_Labels, Character, String);
+ package My_Graphs is new Packrat.Graphs (My_Labels, Character, String, My_Interfaces);
+
+
+ use type My_Interfaces.Cursor;
+ use type My_Graphs.Parse_Graph;
+
+
+ function Node_Check
+ return Test_Result
+ is
+ Leafeon : My_Graphs.Node := My_Graphs.Leaf ("abc", 1, 3);
+ Brancheon : My_Graphs.Node := My_Graphs.Branch (One, 4, 3);
+ begin
+ if Leafeon.Elements /= "abc" or Brancheon.Label /= One or
+ Leafeon.Start /= 1 or Brancheon.Start /= 4 or
+ Leafeon.Finish /= 3 or Brancheon.Finish /= 3
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Node_Check;
+
+
+ function Cursor_Check
+ return Test_Result is
+ begin
+ return Fail;
+ end Cursor_Check;
+
+
+ function Empty_Check
+ return Test_Result is
+ begin
+ if not My_Graphs.Empty_Graph.Is_Empty or not My_Graphs.No_Position.Is_Nothing then
+ return Fail;
+ end if;
+ return Pass;
+ end Empty_Check;
+
+
+ function Attachment_Check
+ return Test_Result is
+ begin
+ return Fail;
+ end Attachment_Check;
+
+
+ function Find_Check
+ return Test_Result
+ is
+ Leafeon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
+ Brancheon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 5));
+ Combined : My_Graphs.Parse_Graph := Brancheon;
+ begin
+ Combined.Attach_Choice (Combined.Root (1), Leafeon);
+ declare
+ Expected_Result : My_Interfaces.Cursor'Class := Combined.Root (1).First_Child;
+ begin
+ if Combined.Find ("abc") /= Expected_Result or
+ Combined.Find ("def") /= My_Graphs.No_Position or
+ Brancheon.Find ("any") /= My_Graphs.No_Position
+ then
+ return Fail;
+ end if;
+ end;
+ return Pass;
+ end Find_Check;
+
+
+ end Graphs;
+
+
+
+
+
package body Util is
diff --git a/test/ratnest-tests.ads b/test/ratnest-tests.ads
index e72bfe7..b8efd8d 100644
--- a/test/ratnest-tests.ads
+++ b/test/ratnest-tests.ads
@@ -120,6 +120,27 @@ package Ratnest.Tests is
+ package Graphs is
+
+ function Node_Check return Test_Result;
+ function Cursor_Check return Test_Result;
+
+ function Empty_Check return Test_Result;
+ function Attachment_Check return Test_Result;
+ function Find_Check return Test_Result;
+
+ Graph_Tests : Test_Array :=
+ ((+"Node", Node_Check'Access),
+ (+"Cursor", Cursor_Check'Access),
+ (+"Emptiness", Empty_Check'Access),
+ (+"Attachment", Attachment_Check'Access),
+ (+"Find", Find_Check'Access));
+
+ end Graphs;
+
+
+
+
package Util is
function In_Set_Check return Test_Result;
diff --git a/test/test_main.adb b/test/test_main.adb
index b87dda5..c741a93 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -48,6 +48,10 @@ begin
Run_Tests (Lexer.Lexer_Tests);
New_Line;
+ Put_Line ("Running tests for Packrat.Graphs...");
+ Run_Tests (Graphs.Graph_Tests);
+ New_Line;
+
Put_Line ("Running tests for Packrat.Util...");
Put_Line ("Testing set predicates...");
Run_Tests (Util.Set_Predicate_Tests);