summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-11-13 11:36:41 +1100
committerJed Barber <jjbarber@y7mail.com>2020-11-13 11:36:41 +1100
commit43eea37daf162473c8c8e8279c9159d8b052ffdf (patch)
treed3fdd283a9b0d1bc5b0a5cafb6b4c18534eeefe5 /test
parent2e075ca317211553a19d7c8706a9d66fabcc9d8d (diff)
Refactored Tokens, Errors, Traits
Diffstat (limited to 'test')
-rw-r--r--test/packrat-lexer-debug.adb4
-rw-r--r--test/packrat-lexer-debug.ads4
-rw-r--r--test/rat_tests-errors.adb2
-rw-r--r--test/rat_tests-lexer.adb140
-rw-r--r--test/rat_tests-parse_graphs.adb45
-rw-r--r--test/rat_tests-tokens.adb2
-rw-r--r--test/test_main.adb3
7 files changed, 103 insertions, 97 deletions
diff --git a/test/packrat-lexer-debug.adb b/test/packrat-lexer-debug.adb
index f6c57ef..40dbd87 100644
--- a/test/packrat-lexer-debug.adb
+++ b/test/packrat-lexer-debug.adb
@@ -76,7 +76,7 @@ package body Packrat.Lexer.Debug is
function Pass
(This : in Lexer_Context)
- return Element_Array is
+ return Traits.Element_Array is
begin
return This.Pass_Forward.Element;
end Pass;
@@ -91,7 +91,7 @@ package body Packrat.Lexer.Debug is
function Element
(Vec : in Token_Vector;
Dex : in Positive)
- return Gen_Tokens.Token is
+ return Traits.Tokens.Token is
begin
return Token_Vectors.Vector (Vec).Element (Dex);
end Element;
diff --git a/test/packrat-lexer-debug.ads b/test/packrat-lexer-debug.ads
index 05d05b2..bd6c2de 100644
--- a/test/packrat-lexer-debug.ads
+++ b/test/packrat-lexer-debug.ads
@@ -52,7 +52,7 @@ package Packrat.Lexer.Debug is
function Pass
(This : in Lexer_Context)
- return Element_Array;
+ return Traits.Element_Array;
function Length
(Vec : in Token_Vector)
@@ -61,7 +61,7 @@ package Packrat.Lexer.Debug is
function Element
(Vec : in Token_Vector;
Dex : in Positive)
- return Gen_Tokens.Token;
+ return Traits.Tokens.Token;
diff --git a/test/rat_tests-errors.adb b/test/rat_tests-errors.adb
index 75d2c34..ee95004 100644
--- a/test/rat_tests-errors.adb
+++ b/test/rat_tests-errors.adb
@@ -1,6 +1,6 @@
-with Packrat;
+with Packrat.Errors;
package body Rat_Tests.Errors is
diff --git a/test/rat_tests-lexer.adb b/test/rat_tests-lexer.adb
index 484c86b..531d175 100644
--- a/test/rat_tests-lexer.adb
+++ b/test/rat_tests-lexer.adb
@@ -2,6 +2,8 @@
with
+ Packrat.Errors,
+ Packrat.Traits,
Packrat.Lexer.Debug,
Packrat.Util;
@@ -15,8 +17,8 @@ package body Rat_Tests.Lexer is
type My_Labels is (One, Two, Three);
- package String_Tokens is new Packrat.Tokens (My_Labels, Character, String);
- package Slexy is new Packrat.Lexer (My_Labels, Character, String, "<", String_Tokens);
+ package Slexy_Traits is new Packrat.Traits (My_Labels, Character, String);
+ package Slexy is new Packrat.Lexer (Slexy_Traits);
package Slebug is new Slexy.Debug;
@@ -553,7 +555,7 @@ package body Rat_Tests.Lexer is
function Stamp_Check
return Test_Result
is
- use type String_Tokens.Token;
+ use type Slexy_Traits.Tokens.Token;
use type Packrat.Result_Status;
use type Slexy.Component_Result;
@@ -576,7 +578,7 @@ package body Rat_Tests.Lexer is
begin
Comp_Code := 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, "abc")) or
+ Slebug.So_Far (Context1).Element (1) /= Slexy_Traits.Tokens.Create (One, 1, "abc")) or
Slebug.Position (Context1) /= 4 or Slebug.Status (Context1) /= Packrat.Success or
Slebug.Has_Pass (Context1)
then
@@ -584,7 +586,7 @@ package body Rat_Tests.Lexer is
end if;
Comp_Code := 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, "abc")) or
+ Slebug.So_Far (Context1).Element (1) /= Slexy_Traits.Tokens.Create (One, 1, "abc")) or
Slebug.Position (Context1) /= 4 or not Slebug.Is_Failure (Comp_Code) or
Slebug.Has_Pass (Context1)
then
@@ -648,12 +650,12 @@ package body Rat_Tests.Lexer is
type Word_Enum is (Blank, Word, Whitespace);
- package Word_Tokens is new Packrat.Tokens (Word_Enum, Character, String);
- package Swordy is new Packrat.Lexer (Word_Enum, Character, String, "<", Word_Tokens);
+ package Swordy_Traits is new Packrat.Traits (Word_Enum, Character, String);
+ package Swordy is new Packrat.Lexer (Swordy_Traits);
package Swolbug is new Swordy.Debug;
- use type Word_Tokens.Token;
- use type Word_Tokens.Token_Array;
+ use type Swordy_Traits.Tokens.Token;
+ use type Swordy_Traits.Tokens.Token_Array;
function Satisfy_Letter is new Swordy.Satisfy (PU.Is_Letter);
function Many_Letter is new Swordy.Many (Satisfy_Letter, 1);
@@ -673,15 +675,15 @@ package body Rat_Tests.Lexer is
Test_Str : String := "one fine day";
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Intended_Result1 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 1, "one"),
- 2 => Word_Tokens.Create (Word, 5, "fine"));
- Intended_Result2 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 10, "day"));
+ Intended_Result1 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"),
+ 2 => Swordy_Traits.Tokens.Create (Word, 5, "fine"));
+ Intended_Result2 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 10, "day"));
- Actual_Result1 : Word_Tokens.Token_Array :=
+ Actual_Result1 : Swordy_Traits.Tokens.Token_Array :=
My_Scan (Test_Str, Test_Context);
- Actual_Result2 : Word_Tokens.Token_Array :=
+ Actual_Result2 : Swordy_Traits.Tokens.Token_Array :=
My_Scan ("", Test_Context);
begin
if Actual_Result1 /= Intended_Result1 or Actual_Result2 /= Intended_Result2 then
@@ -700,12 +702,12 @@ package body Rat_Tests.Lexer is
Test_Str : String := "one fine day";
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Intended_Result : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 1, "one"),
- 2 => Word_Tokens.Create (Word, 5, "fine"),
- 3 => Word_Tokens.Create (Word, 10, "day"));
+ Intended_Result : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"),
+ 2 => Swordy_Traits.Tokens.Create (Word, 5, "fine"),
+ 3 => Swordy_Traits.Tokens.Create (Word, 10, "day"));
- Actual_Result : Word_Tokens.Token_Array :=
+ Actual_Result : Swordy_Traits.Tokens.Token_Array :=
My_Scan (Test_Str, Test_Context);
begin
if Actual_Result /= Intended_Result then
@@ -738,17 +740,17 @@ package body Rat_Tests.Lexer is
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Intended_Result : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 1, "it"),
- 2 => Word_Tokens.Create (Word, 4, "will"),
- 3 => Word_Tokens.Create (Word, 9, "happen"),
- 4 => Word_Tokens.Create (Word, 17, "again"),
- 5 => Word_Tokens.Create (Word, 23, "and"),
- 6 => Word_Tokens.Create (Word, 27, "again"),
- 7 => Word_Tokens.Create (Word, 33, "and"),
- 8 => Word_Tokens.Create (Word, 37, "again"));
-
- Actual_Result : Word_Tokens.Token_Array :=
+ Intended_Result : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 1, "it"),
+ 2 => Swordy_Traits.Tokens.Create (Word, 4, "will"),
+ 3 => Swordy_Traits.Tokens.Create (Word, 9, "happen"),
+ 4 => Swordy_Traits.Tokens.Create (Word, 17, "again"),
+ 5 => Swordy_Traits.Tokens.Create (Word, 23, "and"),
+ 6 => Swordy_Traits.Tokens.Create (Word, 27, "again"),
+ 7 => Swordy_Traits.Tokens.Create (Word, 33, "and"),
+ 8 => Swordy_Traits.Tokens.Create (Word, 37, "again"));
+
+ Actual_Result : Swordy_Traits.Tokens.Token_Array :=
My_Scan (More_Input'Unrestricted_Access, Test_Context);
begin
if Actual_Result /= Intended_Result then
@@ -763,27 +765,27 @@ package body Rat_Tests.Lexer is
is
procedure My_Scan is new Swordy.Scan_Set
((Stamp_Word'Access, Ignore_Whitespace'Access),
- Latin.EOT, Word_Tokens.Create (Blank, 1, ""));
+ Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, ""));
Test_Str1 : String (1 .. 10) := "one tw";
Test_Str2 : String (1 .. 10) := "o three";
Test_Str3 : String (1 .. 10) := Latin.EOT & " ";
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Intended_Result1 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 1, "one"),
- 2 => Word_Tokens.Create (Blank, 1, ""),
- 3 => Word_Tokens.Create (Blank, 1, ""));
- Intended_Result2 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 9, "two"),
- 2 => Word_Tokens.Create (Blank, 1, ""),
- 3 => Word_Tokens.Create (Blank, 1, ""));
- Intended_Result3 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 16, "three"),
- 2 => Word_Tokens.Create (Blank, 1, ""),
- 3 => Word_Tokens.Create (Blank, 1, ""));
-
- Actual_Result : Word_Tokens.Token_Array (1 .. 3);
+ Intended_Result1 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 1, "one"),
+ 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""),
+ 3 => Swordy_Traits.Tokens.Create (Blank, 1, ""));
+ Intended_Result2 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 9, "two"),
+ 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""),
+ 3 => Swordy_Traits.Tokens.Create (Blank, 1, ""));
+ Intended_Result3 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 16, "three"),
+ 2 => Swordy_Traits.Tokens.Create (Blank, 1, ""),
+ 3 => Swordy_Traits.Tokens.Create (Blank, 1, ""));
+
+ Actual_Result : Swordy_Traits.Tokens.Token_Array (1 .. 3);
begin
My_Scan (Test_Str1, Test_Context, Actual_Result);
if Actual_Result /= Intended_Result1 then
@@ -821,24 +823,24 @@ package body Rat_Tests.Lexer is
procedure My_Scan is new Swordy.Scan_Set_With
((Stamp_Word'Access, Ignore_Whitespace'Access),
- Latin.EOT, Word_Tokens.Create (Blank, 1, ""));
+ Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, ""));
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Intended_Result1 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 1, "it"),
- 2 => Word_Tokens.Create (Word, 4, "will"),
- 3 => Word_Tokens.Create (Word, 9, "happen"),
- 4 => Word_Tokens.Create (Word, 16, "again"),
- 5 => Word_Tokens.Create (Word, 22, "and"));
- Intended_Result2 : Word_Tokens.Token_Array :=
- (1 => Word_Tokens.Create (Word, 26, "again"),
- 2 => Word_Tokens.Create (Word, 32, "and"),
- 3 => Word_Tokens.Create (Word, 36, "again"),
- 4 => Word_Tokens.Create (Blank, 1, ""),
- 5 => Word_Tokens.Create (Blank, 1, ""));
-
- Actual_Result : Word_Tokens.Token_Array (1 .. 5);
+ Intended_Result1 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 1, "it"),
+ 2 => Swordy_Traits.Tokens.Create (Word, 4, "will"),
+ 3 => Swordy_Traits.Tokens.Create (Word, 9, "happen"),
+ 4 => Swordy_Traits.Tokens.Create (Word, 16, "again"),
+ 5 => Swordy_Traits.Tokens.Create (Word, 22, "and"));
+ Intended_Result2 : Swordy_Traits.Tokens.Token_Array :=
+ (1 => Swordy_Traits.Tokens.Create (Word, 26, "again"),
+ 2 => Swordy_Traits.Tokens.Create (Word, 32, "and"),
+ 3 => Swordy_Traits.Tokens.Create (Word, 36, "again"),
+ 4 => Swordy_Traits.Tokens.Create (Blank, 1, ""),
+ 5 => Swordy_Traits.Tokens.Create (Blank, 1, ""));
+
+ Actual_Result : Swordy_Traits.Tokens.Token_Array (1 .. 5);
begin
My_Scan (More_Input'Unrestricted_Access, Test_Context, Actual_Result);
if Actual_Result /= Intended_Result1 then
@@ -867,7 +869,7 @@ package body Rat_Tests.Lexer is
((+"WORD", 1), (+"WHITESPACE", 1));
begin
declare
- Result : Word_Tokens.Token_Array := My_Scan (Test_Str, Test_Context);
+ Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context);
begin
return Fail;
end;
@@ -895,7 +897,7 @@ package body Rat_Tests.Lexer is
((+"WORD", 1), (+"WHITESPACE", 1));
begin
declare
- Result : Word_Tokens.Token_Array := My_Scan (Test_Str, Test_Context);
+ Result : Swordy_Traits.Tokens.Token_Array := My_Scan (Test_Str, Test_Context);
begin
return Fail;
end;
@@ -934,7 +936,7 @@ package body Rat_Tests.Lexer is
((+"WORD", 1), (+"WHITESPACE", 1));
begin
declare
- Result : Word_Tokens.Token_Array :=
+ Result : Swordy_Traits.Tokens.Token_Array :=
My_Scan (Get_Input'Unrestricted_Access, Test_Context);
begin
return Fail;
@@ -955,12 +957,12 @@ package body Rat_Tests.Lexer is
procedure My_Scan is new Swordy.Scan_Set
((Stamp_Word'Access, Ignore_Whitespace'Access),
- Latin.EOT, Word_Tokens.Create (Blank, 1, ""));
+ Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, ""));
Test_Str : String := "()()";
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Result : Word_Tokens.Token_Array (1 .. 5);
+ Result : Swordy_Traits.Tokens.Token_Array (1 .. 5);
Expected_Errors : Packrat.Errors.Error_Info_Array :=
((+"WORD", 1), (+"WHITESPACE", 1));
@@ -995,11 +997,11 @@ package body Rat_Tests.Lexer is
procedure My_Scan is new Swordy.Scan_Set_With
((Stamp_Word'Access, Ignore_Whitespace'Access),
- Latin.EOT, Word_Tokens.Create (Blank, 1, ""));
+ Latin.EOT, Swordy_Traits.Tokens.Create (Blank, 1, ""));
Test_Context : Swordy.Lexer_Context := Swordy.Empty_Context;
- Result : Word_Tokens.Token_Array (1 .. 5);
+ Result : Swordy_Traits.Tokens.Token_Array (1 .. 5);
Expected_Errors : Packrat.Errors.Error_Info_Array :=
((+"WORD", 1), (+"WHITESPACE", 1));
diff --git a/test/rat_tests-parse_graphs.adb b/test/rat_tests-parse_graphs.adb
index e445f1b..981bb2c 100644
--- a/test/rat_tests-parse_graphs.adb
+++ b/test/rat_tests-parse_graphs.adb
@@ -1,6 +1,9 @@
-with Packrat.Parse_Graphs;
+with
+
+ Packrat.Traits,
+ Packrat.Parse_Graphs;
package body Rat_Tests.Parse_Graphs is
@@ -10,38 +13,38 @@ package body Rat_Tests.Parse_Graphs is
(Noun, Determiner, Noun_Phrase, Preposition,
Prepositional_Phrase, Verb, Verb_Phrase, Sentence);
- package String_Tokens is new Packrat.Tokens (My_Labels, Character, String);
- package Graphs is new Packrat.Parse_Graphs (My_Labels, Character, String, "<", String_Tokens);
+ package My_Traits is new Packrat.Traits (My_Labels, Character, String);
+ package Graphs is new Packrat.Parse_Graphs (My_Traits);
-- These tokens are defined here purely to reduce verbosity when
-- manually constructing the various test graphs in the package initialisation.
- Noun_1 : String_Tokens.Token := String_Tokens.Create (Noun, 1, "i");
- Noun_4 : String_Tokens.Token := String_Tokens.Create (Noun, 4, "man");
- Noun_7 : String_Tokens.Token := String_Tokens.Create (Noun, 7, "park");
- Noun_10 : String_Tokens.Token := String_Tokens.Create (Noun, 10, "bat");
+ Noun_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 1, "i");
+ Noun_4 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 4, "man");
+ Noun_7 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 7, "park");
+ Noun_10 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun, 10, "bat");
- Det_3 : String_Tokens.Token := String_Tokens.Create (Determiner, 3, "a");
- Det_6 : String_Tokens.Token := String_Tokens.Create (Determiner, 6, "the");
- Det_9 : String_Tokens.Token := String_Tokens.Create (Determiner, 9, "a");
+ Det_3 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 3, "a");
+ Det_6 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 6, "the");
+ Det_9 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Determiner, 9, "a");
- NP_1 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 1, "");
- NP_3 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 3, "");
- NP_6 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 6, "");
- NP_9 : String_Tokens.Token := String_Tokens.Create (Noun_Phrase, 9, "");
+ NP_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 1, "");
+ NP_3 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 3, "");
+ NP_6 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 6, "");
+ NP_9 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Noun_Phrase, 9, "");
- Prep_5 : String_Tokens.Token := String_Tokens.Create (Preposition, 5, "in");
- Prep_8 : String_Tokens.Token := String_Tokens.Create (Preposition, 8, "with");
+ Prep_5 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Preposition, 5, "in");
+ Prep_8 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Preposition, 8, "with");
- PP_5 : String_Tokens.Token := String_Tokens.Create (Prepositional_Phrase, 5, "");
- PP_8 : String_Tokens.Token := String_Tokens.Create (Prepositional_Phrase, 8, "");
+ PP_5 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Prepositional_Phrase, 5, "");
+ PP_8 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Prepositional_Phrase, 8, "");
- Verb_2 : String_Tokens.Token := String_Tokens.Create (Verb, 2, "saw");
+ Verb_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb, 2, "saw");
- VP_2 : String_Tokens.Token := String_Tokens.Create (Verb_Phrase, 2, "");
+ VP_2 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Verb_Phrase, 2, "");
- Sen_1 : String_Tokens.Token := String_Tokens.Create (Sentence, 1, "");
+ Sen_1 : My_Traits.Tokens.Token := My_Traits.Tokens.Create (Sentence, 1, "");
-- This should be set up to be identical to the example parse in the paper
diff --git a/test/rat_tests-tokens.adb b/test/rat_tests-tokens.adb
index 8bfb516..74a3c0a 100644
--- a/test/rat_tests-tokens.adb
+++ b/test/rat_tests-tokens.adb
@@ -1,6 +1,6 @@
-with Packrat;
+with Packrat.Tokens;
package body Rat_Tests.Tokens is
diff --git a/test/test_main.adb b/test/test_main.adb
index 7a96cbd..ebca4fd 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -6,7 +6,8 @@ with
Ada.Command_Line,
Ada.Characters.Latin_1,
Unit_Tests,
- Packrat,
+ Packrat.Errors,
+ Packrat.Tokens,
Rat_Tests.Errors,
Rat_Tests.Tokens,
Rat_Tests.Lexer,