summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ratnest-tests.adb82
-rw-r--r--test/ratnest-tests.ads21
-rw-r--r--test/test_main.adb4
3 files changed, 107 insertions, 0 deletions
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);