summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/packrat-lexer-debug.adb15
-rw-r--r--test/packrat-lexer-debug.ads11
-rw-r--r--test/ratnest-tests.adb157
-rw-r--r--test/ratnest-tests.ads21
-rw-r--r--test/test_main.adb6
5 files changed, 208 insertions, 2 deletions
diff --git a/test/packrat-lexer-debug.adb b/test/packrat-lexer-debug.adb
index f13a675..335e3d2 100644
--- a/test/packrat-lexer-debug.adb
+++ b/test/packrat-lexer-debug.adb
@@ -117,6 +117,21 @@ package body Packrat.Lexer.Debug is
return This.Pass_Forward;
end Pass;
+ function Length
+ (Vec : in Token_Vector)
+ return Natural is
+ begin
+ return Integer (Token_Vectors.Vector (Vec).Length);
+ end Length;
+
+ function Element
+ (Vec : in Token_Vector;
+ Dex : in Positive)
+ return Gen_Tokens.Token is
+ begin
+ return Token_Vectors.Vector (Vec).Element (Dex);
+ end Element;
+
end Packrat.Lexer.Debug;
diff --git a/test/packrat-lexer-debug.ads b/test/packrat-lexer-debug.ads
index e68d6f4..77614aa 100644
--- a/test/packrat-lexer-debug.ads
+++ b/test/packrat-lexer-debug.ads
@@ -33,7 +33,7 @@ package Packrat.Lexer.Debug is
- type Token_Vector is private;
+ type Token_Vector is tagged private;
function So_Far
(This : in Lexer_Context)
@@ -51,6 +51,15 @@ package Packrat.Lexer.Debug is
(This : in Lexer_Context)
return access Element_Array;
+ function Length
+ (Vec : in Token_Vector)
+ return Natural;
+
+ function Element
+ (Vec : in Token_Vector;
+ Dex : in Positive)
+ return Gen_Tokens.Token;
+
private
diff --git a/test/ratnest-tests.adb b/test/ratnest-tests.adb
index ebe4dae..f9353f3 100644
--- a/test/ratnest-tests.adb
+++ b/test/ratnest-tests.adb
@@ -765,6 +765,163 @@ package body Ratnest.Tests is
end Input_End_Check;
+
+
+
+ function Stamp_Check
+ return Test_Result
+ is
+ use type String_Tokens.Token;
+ use type Packrat.Result_Status;
+
+ function Match_A is new Slexy.Match ('a');
+ function Match_B is new Slexy.Match ('b');
+ function Match_C is new Slexy.Match ('c');
+ function Seq_Abc is new Slexy.Sequence
+ ((Match_A'Unrestricted_Access,
+ Match_B'Unrestricted_Access,
+ Match_C'Unrestricted_Access));
+ procedure My_Stamp is new Slexy.Stamp (One, Seq_Abc);
+
+ Test_Str1 : String := "abcdefghi";
+ Test_Str2 : String := "ab";
+
+ Context1 : Slexy.Lexer_Context := Slexy.Empty_Context;
+ Context2 : Slexy.Lexer_Context := Slexy.Empty_Context;
+ begin
+ My_Stamp (Test_Str1, Context1);
+ if (Slebug.So_Far (Context1).Length /= 1 or else
+ Slebug.So_Far (Context1).Element (1) /= String_Tokens.Create (One, 1, 3, "abc")) or
+ Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Success or
+ Slebug.Pass (Context1) /= null
+ then
+ return Fail;
+ end if;
+ My_Stamp (Test_Str1, Context1);
+ if (Slebug.So_Far (Context1).Length /= 1 or else
+ Slebug.So_Far (Context1).Element (1) /= String_Tokens.Create (One, 1, 3, "abc")) or
+ Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Failure or
+ Slebug.Pass (Context1) /= null
+ then
+ return Fail;
+ end if;
+ My_Stamp (Test_Str2, Context2);
+ if Slebug.So_Far (Context2).Length /= 0 or
+ Slebug.Position (Context2) /= 1 or
+ Slebug.Status (Context2) /= Packrat.Needs_More or
+ (Slebug.Pass (Context2) = null or else Slebug.Pass (Context2).all /= "ab")
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Stamp_Check;
+
+
+ function Ignore_Check
+ return Test_Result
+ is
+ use type Packrat.Result_Status;
+
+ function Match_Abc is new Slexy.Multimatch ("abc");
+ procedure My_Ignore is new Slexy.Ignore (Match_Abc);
+
+ Test_Str1 : String := "abcdefghi";
+ Test_Str2 : String := "ab";
+
+ Context1 : Slexy.Lexer_Context := Slexy.Empty_Context;
+ Context2 : Slexy.Lexer_Context := Slexy.Empty_Context;
+ begin
+ My_Ignore (Test_Str1, Context1);
+ if Slebug.So_Far (Context1).Length /= 0 or
+ Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Success or
+ Slebug.Pass (Context1) /= null
+ then
+ return Fail;
+ end if;
+ My_Ignore (Test_Str1, Context1);
+ if Slebug.So_Far (Context1).Length /= 0 or
+ Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Failure or
+ Slebug.Pass (Context1) /= null
+ then
+ return Fail;
+ end if;
+ My_Ignore (Test_Str2, Context2);
+ if Slebug.So_Far (Context2).Length /= 0 or
+ Slebug.Position (Context2) /= 1 or Slebug.Status (Context2) /= Packrat.Needs_More or
+ (Slebug.Pass (Context2) = null or else Slebug.Pass (Context2).all /= "ab")
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Ignore_Check;
+
+
+
+
+
+ type Word_Enum is (Word);
+
+ package Word_Tokens is new Packrat.Tokens (Word_Enum, Character, String);
+ package Swordy is new Packrat.Lexer (Word_Enum, Character, String, Word_Tokens);
+ package Swolbug is new Swordy.Debug;
+
+ function Satisfy_Letter is new Swordy.Satisfy (PU.Is_Letter);
+ function Many_Letter is new Swordy.Many (Satisfy_Letter, 1);
+ function Satisfy_Whitespace is new Swordy.Satisfy (PU.Is_Whitespace);
+ function Many_Whitespace is new Swordy.Many (Satisfy_Whitespace, 1);
+
+ procedure Stamp_Word is new Swordy.Stamp (Word, Many_Letter);
+ procedure Ignore_Whitespace is new Swordy.Ignore (Many_Whitespace);
+
+
+ function Scan_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_Check;
+
+
+ function Scan_Set_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_Set_Check;
+
+
+ function Scan_Only_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_Only_Check;
+
+
+ function Scan_Set_Only_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_Set_Only_Check;
+
+
+ function Scan_With_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_With_Check;
+
+
+ function Scan_Set_With_Check
+ return Test_Result
+ is
+ begin
+ return Fail;
+ end Scan_Set_With_Check;
+
+
end Lexer;
diff --git a/test/ratnest-tests.ads b/test/ratnest-tests.ads
index 9febd35..f795340 100644
--- a/test/ratnest-tests.ads
+++ b/test/ratnest-tests.ads
@@ -85,6 +85,27 @@ package Ratnest.Tests is
(+"Line End", Line_End_Check'Access),
(+"Input_End", Input_End_Check'Access));
+
+ function Stamp_Check return Test_Result;
+ function Ignore_Check return Test_Result;
+
+ function Scan_Check return Test_Result;
+ function Scan_Set_Check return Test_Result;
+ function Scan_Only_Check return Test_Result;
+ function Scan_Set_Only_Check return Test_Result;
+ function Scan_With_Check return Test_Result;
+ function Scan_Set_With_Check return Test_Result;
+
+ Lexer_Tests : Test_Array :=
+ ((+"Stamp", Stamp_Check'Access),
+ (+"Ignore", Ignore_Check'Access),
+ (+"Scan", Scan_Check'Access),
+ (+"Scan_Set", Scan_Set_Check'Access),
+ (+"Scan_Only", Scan_Only_Check'Access),
+ (+"Scan_Set_Only", Scan_Set_Only_Check'Access),
+ (+"Scan_With", Scan_With_Check'Access),
+ (+"Scan_Set_With", Scan_Set_With_Check'Access));
+
end Lexer;
diff --git a/test/test_main.adb b/test/test_main.adb
index 4915a5c..b87dda5 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -40,10 +40,14 @@ begin
Put (Tok.Debug_String);
New_Line;
- Put_Line ("Running tests for Packrat.Lexer.Combinators...");
+ Put_Line ("Running tests for Packrat.Lexer combinators...");
Run_Tests (Lexer.Combinator_Tests);
New_Line;
+ Put_Line ("Running tests for Packrat.Lexer lexing...");
+ Run_Tests (Lexer.Lexer_Tests);
+ New_Line;
+
Put_Line ("Running tests for Packrat.Util...");
Put_Line ("Testing set predicates...");
Run_Tests (Util.Set_Predicate_Tests);