summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-12 00:38:45 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-12 00:38:45 +1100
commitdc3078a06b5ee52751cfb6fd6cf13b3790632ac4 (patch)
tree25187b953479f943947e919b7acc1f4a3ca41fe6 /test
parent554d2ab14921c48d628b0ffa86cc7492836477ac (diff)
Packrat.Lexer.Combinators specs and tests complete
Diffstat (limited to 'test')
-rw-r--r--test/ratnest-tests.adb711
-rw-r--r--test/ratnest-tests.ads7
-rw-r--r--test/ratnest.adb2
-rw-r--r--test/ratnest.ads2
4 files changed, 567 insertions, 155 deletions
diff --git a/test/ratnest-tests.adb b/test/ratnest-tests.adb
index 0603d09..2613a65 100644
--- a/test/ratnest-tests.adb
+++ b/test/ratnest-tests.adb
@@ -34,9 +34,9 @@ package body Ratnest.Tests is
not PE.Valid_Message ("sNAMEp34sSYMp02") or not PE.Valid_Message ("") or
not PE.Valid_Message ("sA_Bp3") or not PE.Valid_Message ("sAp1sAp1")
then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Valid_Message_Check;
@@ -52,22 +52,22 @@ package body Ratnest.Tests is
if not PE.Valid_Identifier (EI.Symbol) or
not PE.Valid_Identifier (-EI.Symbol)
then
- return Failure;
+ return Fail;
end if;
end loop;
for EI of Fail_Array loop
if PE.Valid_Identifier (EI.Symbol) or
PE.Valid_Identifier (-EI.Symbol)
then
- return Failure;
+ return Fail;
end if;
end loop;
if not PE.Valid_Identifier_Array (Pass_Array) or
PE.Valid_Identifier_Array (Fail_Array)
then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Valid_Identifier_Check;
@@ -97,9 +97,9 @@ package body Ratnest.Tests is
Msg_8 : PE.Error_Message := PE.Encode_Array (Array_8);
begin
if Msg_3 /= Msg_4 or Msg_7 /= Msg_8 then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Join_Check;
@@ -108,9 +108,9 @@ package body Ratnest.Tests is
begin
-- Encode with a String and a Natural
if PE.Encode ("ABC", 15) /= "sABCp15" then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Encode_1_Check;
@@ -119,9 +119,9 @@ package body Ratnest.Tests is
begin
-- Encode with an Unbounded_String and a Natural
if PE.Encode (+"ABC", 15) /= "sABCp15" then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Encode_2_Check;
@@ -130,9 +130,9 @@ package body Ratnest.Tests is
begin
-- Encode with an Error_Info
if PE.Encode ((+"ABC", 15)) /= "sABCp15" then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Encode_3_Check;
@@ -143,9 +143,9 @@ package body Ratnest.Tests is
if PE.Encode_Array (((+"A", 3), (+"BC", 2), (+"ABC", 1), (+"B", 4))) /=
"sAp3sBCp2sABCp1sBp4"
then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Encode_4_Check;
@@ -157,9 +157,9 @@ package body Ratnest.Tests is
if PE.Decode ("sAp1sBp3sCp10sDEFp456") /=
((+"A", 1), (+"B", 3), (+"C", 10), (+"DEF", 456))
then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Decode_Check;
@@ -172,12 +172,13 @@ package body Ratnest.Tests is
package body Tokens is
+ type My_Labels is (One, Two, Three);
+ package My_Tokens is new Packrat.Tokens (My_Labels, Character, String);
+
+
function Adjust_Check
return Test_Result
is
- type My_Labels is (One, Two, Three);
- package My_Tokens is new Packrat.Tokens (My_Labels, Character, String);
-
A : My_Tokens.Token;
begin
declare
@@ -186,18 +187,29 @@ package body Ratnest.Tests is
A := B;
end;
if not A.Initialized or else A.Value /= "abc" then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Adjust_Check;
- function Store_Check
+ function Equals_Check
return Test_Result
is
- type My_Labels is (One, Two, Three);
- package My_Tokens is new Packrat.Tokens (My_Labels, Character, String);
+ use type My_Tokens.Token;
+ A : My_Tokens.Token := My_Tokens.Create (One, 1, 3, "abc");
+ B : My_Tokens.Token := My_Tokens.Create (One, 1, 3, "abc");
+ begin
+ if A /= B then
+ return Fail;
+ end if;
+ return Pass;
+ end Equals_Check;
+
+ function Store_Check
+ return Test_Result
+ is
T : My_Tokens.Token := My_Tokens.Create (One, 1, 3, "abc");
begin
if not T.Initialized or else
@@ -205,9 +217,9 @@ package body Ratnest.Tests is
T.Start /= 1 or else T.Finish /= 3 or else
T.Value /= "abc"
then
- return Failure;
+ return Fail;
end if;
- return Success;
+ return Pass;
end Store_Check;
@@ -220,115 +232,510 @@ package body Ratnest.Tests is
package body 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 Strombo is new Slexy.Combinators;
+
+
+ use type Slexy.Combinator_Result;
+
+
+
+
+
+ function Join_Check
+ return Test_Result
+ is
+ One : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "a");
+ Two : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Success, "bc");
+ Three : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "abc");
+
+ Four : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Failure, "xyz");
+ Five : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Failure, "axyz");
+
+ Six : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Partial, "cd");
+ Seven : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Partial, "acd");
+ begin
+ if One.Join (Two) /= Three or One.Join (Four) /= Five or
+ One.Join (Six) /= Seven or Four.Join (Six) /= Four or
+ Five.Join (Two) /= Five or Six.Join (Three) /= Six or
+ Slexy.Fail_Result.Join (One) /= Slexy.Fail_Result
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Join_Check;
+
+
+
+
+
function Sequence_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_A is new Strombo.Match ('a');
+ function Match_B is new Strombo.Match ('b');
+ function Match_C is new Strombo.Match ('c');
+ function Seq_Abc is new Strombo.Sequence
+ ((Match_A'Unrestricted_Access,
+ Match_B'Unrestricted_Access,
+ Match_C'Unrestricted_Access));
+
+ Test_Str : String := "aababcabcab";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Partial, "a");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Partial, "ab");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "abc");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Seq_Abc (Test_Str, 1) /= Result1 or Seq_Abc (Test_Str, 2) /= Result2 or
+ Seq_Abc (Test_Str, 4) /= Result3 or Seq_Abc (Test_Str, 10) /= Result2 or
+ Seq_Abc (Test_Str, 3) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Sequence_Check;
function Count_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_A is new Strombo.Match ('a');
+ function Match_B is new Strombo.Match ('b');
+ function Count_2A is new Strombo.Count (Match_A, 2);
+ function Count_3B is new Strombo.Count (Match_B, 3);
+
+ Test_Str : String := "abaabbaaabbbaaaabbbb";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Partial, "a");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Success, "aa");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Partial, "b");
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Partial, "bb");
+ Result5 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "bbb");
+ Result6 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Count_2A (Test_Str, 1) /= Result1 or Count_2A (Test_Str, 3) /= Result2 or
+ Count_3B (Test_Str, 2) /= Result3 or Count_3B (Test_Str, 5) /= Result4 or
+ Count_3B (Test_Str, 10) /= Result5 or Count_3B (Test_Str, 1) /= Result6 or
+ Count_2A (Test_Str, 2) /= Result6 or Count_3B (Test_Str, 19) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Count_Check;
function Many_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_A is new Strombo.Match ('a');
+ function Many_0 is new Strombo.Many (Match_A);
+ function Many_4 is new Strombo.Many (Match_A, 4);
+
+ Test_Str : String := "aaabbaaaaab";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "aaa");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Partial, "aaa");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, "aaaaa");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Many_0 (Test_Str, 1) /= Result1 or Many_4 (Test_Str, 1) /= Result2 or
+ Many_4 (Test_Str, 6) /= Result3 or Many_0 (Test_Str, 4) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Many_Check;
function Many_Until_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_A is new Strombo.Match ('a');
+ function Many_Until_0 is new Strombo.Many_Until (Match_A, PU.Is_Digit);
+ function Many_Until_3 is new Strombo.Many_Until (Match_A, PU.Is_Digit, 3);
+
+ Test_Str : String := "aaaabbaa123aaa4";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Partial, "aaaa");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Success, "aa");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Partial, "aa");
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "aaa");
+ Result5 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Many_Until_0 (Test_Str, 1) /= Result1 or
+ Many_Until_0 (Test_Str, 7) /= Result2 or
+ Many_Until_3 (Test_Str, 7) /= Result3 or
+ Many_Until_3 (Test_Str, 12) /= Result4 or
+ Many_Until_0 (Test_Str, 5) /= Result5
+ then
+ return Fail;
+ end if;
+ return Pass;
end Many_Until_Check;
function Satisfy_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Is_123
+ (Char : in Character)
+ return Boolean is
+ begin
+ return Char = '1' or Char = '2' or Char = '3';
+ end Is_123;
+ function Is_Abc
+ (Char : in Character)
+ return Boolean is
+ begin
+ return Char = 'a' or Char = 'b' or Char = 'c';
+ end Is_Abc;
+
+ function Satisfy_123 is new Strombo.Satisfy (Is_123);
+ function Satisfy_Abc is new Strombo.Satisfy (Is_Abc);
+
+ Test_Str : String := "abc123456def";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "b");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "3");
+ Result3 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Satisfy_123 (Test_Str, 6) /= Result2 or
+ Satisfy_Abc (Test_Str, 2) /= Result1 or
+ Satisfy_Abc (Test_Str, 8) /= Result3
+ then
+ return Fail;
+ end if;
+ return Pass;
end Satisfy_Check;
function Satisfy_With_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Is_Abc
+ (Char : in Character)
+ return Boolean is
+ begin
+ return Char = 'a' or Char = 'b' or Char = 'c';
+ end Is_Abc;
+ function Is_123
+ (Char : in Character)
+ return Boolean is
+ begin
+ return Char = '1' or Char = '2' or Char = '3';
+ end Is_123;
+ function Minus_One
+ (Char : in Character)
+ return Character is
+ begin
+ return Character'Val (Character'Pos (Char) - 1);
+ end Minus_One;
+
+ function Satisfy_Bcd is new Strombo.Satisfy_With (Is_Abc, Minus_One);
+ function Satisfy_234 is new Strombo.Satisfy_With (Is_123, Minus_One);
+
+ Test_Str : String := "abcde12345";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "c");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "2");
+ Result3 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Satisfy_Bcd (Test_Str, 3) /= Result1 or
+ Satisfy_234 (Test_Str, 7) /= Result2 or
+ Satisfy_Bcd (Test_Str, 1) /= Result3
+ then
+ return Fail;
+ end if;
+ return Pass;
end Satisfy_With_Check;
function Match_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_A is new Strombo.Match ('a');
+ function Match_Slash is new Strombo.Match ('/');
+ function Match_4 is new Strombo.Match ('4');
+
+ Test_Str : String := "abc1234./5";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "a");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "/");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "4");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Match_A (Test_Str, 1) /= Result1 or
+ Match_Slash (Test_Str, 9) /= Result2 or
+ Match_4 (Test_Str, 7) /= Result3 or
+ Match_A (Test_Str, 3) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Match_Check;
function Match_With_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Plus_One
+ (Char : in Character)
+ return Character is
+ begin
+ return Character'Val (Character'Pos (Char) + 1);
+ end Plus_One;
+
+ function Match_A is new Strombo.Match_With ('b', Plus_One);
+ function Match_6 is new Strombo.Match_With ('7', Plus_One);
+
+ Test_Str : String := "abc5678";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "a");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "6");
+ Result3 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Match_A (Test_Str, 1) /= Result1 or
+ Match_6 (Test_Str, 5) /= Result2 or
+ Match_A (Test_Str, 2) /= Result3
+ then
+ return Fail;
+ end if;
+ return Pass;
end Match_With_Check;
function Multimatch_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Match_String1 is new Strombo.Multimatch ("abc");
+ function Match_String2 is new Strombo.Multimatch ("hello");
+
+ Test_Str : String := "abcdefabhelloworld";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "abc");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Partial, "ab");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, "hello");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Match_String1 (Test_Str, 1) /= Result1 or
+ Match_String1 (Test_Str, 7) /= Result2 or
+ Match_String2 (Test_Str, 9) /= Result3 or
+ Match_String2 (Test_Str, 3) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Multimatch_Check;
function Take_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Take_1 is new Strombo.Take;
+ function Take_5 is new Strombo.Take (5);
+
+ Test_Str : String := "abcdefghi";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "b");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Partial, "ghi");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, "cdefg");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Take_1 (Test_Str, 2) /= Result1 or Take_5 (Test_Str, 7) /= Result2 or
+ Take_5 (Test_Str, 3) /= Result3 or Take_1 (Test_Str, 11) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Take_Check;
function Take_While_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Take_Letters is new Strombo.Take_While (PU.Is_Letter);
+ function Take_Punch is new Strombo.Take_While (PU.Is_Punctuation);
+
+ Test_Str : String := "abcde,./;'fghi[]=-^563";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Success, "bcde");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Success, "hi");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, ",./;'");
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "=-^");
+ Result5 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Take_Letters (Test_Str, 2) /= Result1 or
+ Take_Letters (Test_Str, 13) /= Result2 or
+ Take_Punch (Test_Str, 6) /= Result3 or
+ Take_Punch (Test_Str, 17) /= Result4 or
+ Take_Letters (Test_Str, 7) /= Result5
+ then
+ return Fail;
+ end if;
+ return Pass;
end Take_While_Check;
function Take_Until_Check
- return Test_Result is
+ return Test_Result
+ is
+ function Take_Till_Punch is new Strombo.Take_Until (PU.Is_Punctuation);
+ function Take_Till_Digit is new Strombo.Take_Until (PU.Is_Digit);
+
+ Test_Str : String := "abcde12345;;;fghi67";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (7, Packrat.Success, "de12345");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Partial, "hi67");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, "abcde");
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (6, Packrat.Success, ";;fghi");
+ Result5 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if Take_Till_Punch (Test_Str, 4) /= Result1 or
+ Take_Till_Punch (Test_Str, 16) /= Result2 or
+ Take_Till_Digit (Test_Str, 1) /= Result3 or
+ Take_Till_Digit (Test_Str, 12) /= Result4 or
+ Take_Till_Punch (Test_Str, 20) /= Result5
+ then
+ return Fail;
+ end if;
+ return Pass;
end Take_Until_Check;
function Line_Start_Check
- return Test_Result is
+ return Test_Result
+ is
+ function LF_Start is new Strombo.Line_Start (Latin.LF);
+ function C_Start is new Strombo.Line_Start ('c');
+
+ Test_Str : String := "abcd" & Latin.LF & "e";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (0, Packrat.Success, "");
+ Result2 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if LF_Start (Test_Str, 6) /= Result1 or C_Start (Test_Str, 4) /= Result1 or
+ LF_Start (Test_Str, 2) /= Result2 or C_Start (Test_Str, 1) /= Result2
+ then
+ return Fail;
+ end if;
+ return Pass;
end Line_Start_Check;
function Line_End_Check
- return Test_Result is
+ return Test_Result
+ is
+ function LF_End is new Strombo.Line_End (Latin.LF);
+ function C_End is new Strombo.Line_End ('c');
+
+ Test_Str : String := "abcd" & Latin.LF & "e";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "" & Latin.LF);
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "c");
+ Result3 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if LF_End (Test_Str, 5) /= Result1 or C_End (Test_Str, 3) /= Result2 or
+ LF_End (Test_Str, 7) /= Result3 or LF_End (Test_Str, 1) /= Result3
+ then
+ return Fail;
+ end if;
+ return Pass;
end Line_End_Check;
function Input_Start_Check
- return Test_Result is
+ return Test_Result
+ is
+ Test_Str : String := "abcde";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (0, Packrat.Success, "");
begin
- return Failure;
+ if Strombo.Input_Start (Test_Str, 1) /= Result1 or
+ Strombo.Input_Start (Test_Str, 3) /= Slexy.Fail_Result
+ then
+ return Fail;
+ end if;
+ return Pass;
end Input_Start_Check;
function Input_End_Check
- return Test_Result is
+ return Test_Result
+ is
+ function C_End is new Strombo.Input_End ('c');
+ function E_End is new Strombo.Input_End ('e');
+
+ Test_Str : String := "abcde";
+
+ Result1 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "e");
+ Result2 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (1, Packrat.Success, "c");
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (0, Packrat.Success, "");
+ Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
begin
- return Failure;
+ if C_End (Test_Str, 3) /= Result2 or E_End (Test_Str, 5) /= Result1 or
+ C_End (Test_Str, 6) /= Result3 or E_End (Test_Str, 6) /= Result3 or
+ C_End (Test_Str, 1) /= Result4
+ then
+ return Fail;
+ end if;
+ return Pass;
end Input_End_Check;
@@ -353,46 +760,46 @@ package body Ratnest.Tests is
-- Func_1 testing
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('a') - 1 loop
if Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'a' .. 'c' loop
if not Func_1 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('c') + 1 .. Character'Pos ('x') - 1 loop
if Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'x' .. 'z' loop
if not Func_1 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('z') + 1 .. Character'Pos (Character'Last) loop
if Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
-- Func_2 testing
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('!') - 1 loop
if Func_2 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '!' .. '$' loop
if not Func_2 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('$') + 1 .. Character'Pos (Character'Last) loop
if Func_2 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end In_Set_Check;
@@ -408,46 +815,46 @@ package body Ratnest.Tests is
-- Func_1 testing
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('a') - 1 loop
if not Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'a' .. 'c' loop
if Func_1 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('c') + 1 .. Character'Pos ('x') - 1 loop
if not Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'x' .. 'z' loop
if Func_1 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('z') + 1 .. Character'Pos (Character'Last) loop
if not Func_1 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
-- Func_2 testing
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('!') - 1 loop
if not Func_2 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '!' .. '$' loop
if Func_2 (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('$') + 1 .. Character'Pos (Character'Last) loop
if not Func_2 (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Not_In_Set_Check;
@@ -459,20 +866,20 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('0') - 1 loop
if PU.Is_Digit (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '0' .. '9' loop
if not PU.Is_Digit (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('9') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Digit (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Digit_Check;
@@ -481,40 +888,40 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('0') - 1 loop
if PU.Is_Hex (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '0' .. '9' loop
if not PU.Is_Hex (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('9') + 1 .. Character'Pos ('A') - 1 loop
if PU.Is_Hex (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'A' .. 'F' loop
if not PU.Is_Hex (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('F') + 1 .. Character'Pos ('a') - 1 loop
if PU.Is_Hex (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'a' .. 'f' loop
if not PU.Is_Hex (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('f') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Hex (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Hex_Check;
@@ -523,30 +930,30 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('A') - 1 loop
if PU.Is_Letter (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'A' .. 'Z' loop
if not PU.Is_Letter (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('Z') + 1 .. Character'Pos ('a') - 1 loop
if PU.Is_Letter (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'a' .. 'z' loop
if not PU.Is_Letter (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('z') + 1 .. Character'Pos (Character'First) loop
if PU.Is_Letter (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Letter_Check;
@@ -555,40 +962,40 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('0') - 1 loop
if PU.Is_Alphanumeric (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '0' .. '9' loop
if not PU.Is_Alphanumeric (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('9') + 1 .. Character'Pos ('A') - 1 loop
if PU.Is_Alphanumeric (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'A' .. 'Z' loop
if not PU.Is_Alphanumeric (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('Z') + 1 .. Character'Pos ('a') - 1 loop
if PU.Is_Alphanumeric (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range 'a' .. 'z' loop
if not PU.Is_Alphanumeric (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('z') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Alphanumeric (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Alphanumeric_Check;
@@ -597,50 +1004,50 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos ('!') - 1 loop
if PU.Is_Punctuation (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '!' .. '/' loop
if not PU.Is_Punctuation (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('/') + 1 .. Character'Pos (':') - 1 loop
if PU.Is_Punctuation (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range ':' .. '@' loop
if not PU.Is_Punctuation (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('@') + 1 .. Character'Pos ('[') - 1 loop
if PU.Is_Punctuation (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '[' .. '`' loop
if not PU.Is_Punctuation (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('`') + 1 .. Character'Pos ('{') - 1 loop
if PU.Is_Punctuation (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range '{' .. '~' loop
if not PU.Is_Punctuation (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos ('~') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Punctuation (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Punctuation_Check;
@@ -649,15 +1056,15 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. 127 loop
if not PU.Is_ASCII (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range 128 .. Character'Pos (Character'Last) loop
if PU.Is_ASCII (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_ASCII_Check;
@@ -666,15 +1073,15 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. 127 loop
if PU.Is_Extended_ASCII (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range 128 .. Character'Pos (Character'Last) loop
if not PU.Is_Extended_ASCII (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Extended_ASCII_Check;
@@ -683,18 +1090,18 @@ package body Ratnest.Tests is
begin
for I in Integer range Character'Pos (Character'First) .. Character'Pos (' ') - 1 loop
if PU.Is_Space (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_Space (' ') then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (' ') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Space (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Space_Check;
@@ -705,26 +1112,26 @@ package body Ratnest.Tests is
Character'Pos (Character'First) .. Character'Pos (Latin.HT) - 1
loop
if PU.Is_Linespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_Linespace (Latin.HT) then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (Latin.HT) + 1 .. Character'Pos (' ') - 1 loop
if PU.Is_Linespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_Linespace (' ') then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (' ') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Linespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Linespace_Check;
@@ -735,28 +1142,28 @@ package body Ratnest.Tests is
Character'Pos (Character'First) .. Character'Pos (Latin.LF) - 1
loop
if PU.Is_End_Of_Line (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_End_Of_Line (Latin.LF) then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (Latin.LF) + 1 .. Character'Pos (Latin.CR) - 1 loop
if PU.Is_End_Of_Line (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_End_Of_Line (Latin.CR) then
- return Failure;
+ return Fail;
end if;
for I in Integer range
Character'Pos (Latin.CR) + 1 .. Character'Pos (Character'Last)
loop
if PU.Is_End_Of_Line (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_End_Of_Line_Check;
@@ -767,36 +1174,36 @@ package body Ratnest.Tests is
Character'Pos (Character'First) .. Character'Pos (Latin.HT) - 1
loop
if PU.Is_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range Latin.HT .. Latin.LF loop
if not PU.Is_Whitespace (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos (Latin.LF) + 1 .. Character'Pos (Latin.CR) - 1 loop
if PU.Is_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_Whitespace (Latin.CR) then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (Latin.CR) + 1 .. Character'Pos (' ') - 1 loop
if PU.Is_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if not PU.Is_Whitespace (' ') then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (' ') + 1 .. Character'Pos (Character'Last) loop
if PU.Is_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Is_Whitespace_Check;
@@ -807,36 +1214,36 @@ package body Ratnest.Tests is
Character'Pos (Character'First) .. Character'Pos (Latin.HT) - 1
loop
if not PU.Not_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
for C in Character range Latin.HT .. Latin.LF loop
if PU.Not_Whitespace (C) then
- return Failure;
+ return Fail;
end if;
end loop;
for I in Integer range Character'Pos (Latin.LF) + 1 .. Character'Pos (Latin.CR) - 1 loop
if not PU.Not_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if PU.Not_Whitespace (Latin.CR) then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (Latin.CR) + 1 .. Character'Pos (' ') - 1 loop
if not PU.Not_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
if PU.Not_Whitespace (' ') then
- return Failure;
+ return Fail;
end if;
for I in Integer range Character'Pos (' ') + 1 .. Character'Pos (Character'Last) loop
if not PU.Not_Whitespace (Character'Val (I)) then
- return Failure;
+ return Fail;
end if;
end loop;
- return Success;
+ return Pass;
end Not_Whitespace_Check;
diff --git a/test/ratnest-tests.ads b/test/ratnest-tests.ads
index cc67120..5610db5 100644
--- a/test/ratnest-tests.ads
+++ b/test/ratnest-tests.ads
@@ -32,10 +32,12 @@ package Ratnest.Tests is
package Tokens is
function Adjust_Check return Test_Result;
+ function Equals_Check return Test_Result;
function Store_Check return Test_Result;
Tests : Test_Array :=
((+"Adjust", Adjust_Check'Access),
+ (+"Equals", Equals_Check'Access),
(+"Storage", Store_Check'Access));
end Tokens;
@@ -45,6 +47,8 @@ package Ratnest.Tests is
package Lexer is
+ function Join_Check return Test_Result;
+
function Sequence_Check return Test_Result;
function Count_Check return Test_Result;
function Many_Check return Test_Result;
@@ -65,7 +69,8 @@ package Ratnest.Tests is
function Input_End_Check return Test_Result;
Combinator_Tests : Test_Array :=
- ((+"Sequence", Sequence_Check'Access),
+ ((+"Join", Join_Check'Access),
+ (+"Sequence", Sequence_Check'Access),
(+"Count", Count_Check'Access),
(+"Many", Many_Check'Access),
(+"Many_Until", Many_Until_Check'Access),
diff --git a/test/ratnest.adb b/test/ratnest.adb
index 8d1493c..d063b41 100644
--- a/test/ratnest.adb
+++ b/test/ratnest.adb
@@ -19,7 +19,7 @@ package body Ratnest is
Failed_Count : Natural := 0;
begin
for T of To_Run loop
- if T.Func.all = Failure then
+ if T.Func.all = Fail then
Put_Line ("Failed test " & (-T.Name));
Failed_Count := Failed_Count + 1;
end if;
diff --git a/test/ratnest.ads b/test/ratnest.ads
index adf2369..24a5162 100644
--- a/test/ratnest.ads
+++ b/test/ratnest.ads
@@ -8,7 +8,7 @@ with
package Ratnest is
- type Test_Result is (Failure, Success);
+ type Test_Result is (Fail, Pass);
type Test_Function is access function return Test_Result;