summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-13 00:30:24 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-13 00:30:24 +1100
commit3526877189d0787eb16f23fc233c21be3475c9c7 (patch)
tree59784cd6cfb1980fee7f009aae48d83992bbd213
parentdc3078a06b5ee52751cfb6fd6cf13b3790632ac4 (diff)
Revised tests and notes
-rw-r--r--packrat_parser_lib_notes.txt2
-rw-r--r--test/ratnest-tests.adb201
-rw-r--r--test/ratnest-tests.ads6
3 files changed, 107 insertions, 102 deletions
diff --git a/packrat_parser_lib_notes.txt b/packrat_parser_lib_notes.txt
index b85abfe..d292a94 100644
--- a/packrat_parser_lib_notes.txt
+++ b/packrat_parser_lib_notes.txt
@@ -230,9 +230,7 @@ Take
Take_While
Take_Until
-Line_Start
Line_End
-Input_Start
Input_End
diff --git a/test/ratnest-tests.adb b/test/ratnest-tests.adb
index 2613a65..0fac8cd 100644
--- a/test/ratnest-tests.adb
+++ b/test/ratnest-tests.adb
@@ -262,14 +262,23 @@ package body Ratnest.Tests is
Slexy.Create_Result (4, Packrat.Failure, "axyz");
Six : Slexy.Combinator_Result :=
- Slexy.Create_Result (4, Packrat.Partial, "cd");
+ Slexy.Create_Result (4, Packrat.Needs_More, "cd");
Seven : Slexy.Combinator_Result :=
- Slexy.Create_Result (5, Packrat.Partial, "acd");
+ Slexy.Create_Result (5, Packrat.Needs_More, "acd");
+
+ Eight : Slexy.Combinator_Result :=
+ Slexy.Create_Result (4, Packrat.Failure, "cd");
+
+ Nine : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Optional_More, "abc");
+ Ten : Slexy.Combinator_Result :=
+ Slexy.Create_Result (5, Packrat.Success, "abcbc");
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
+ Five.Join (Two) /= Five or Six.Join (Three) /= Eight or
+ Slexy.Empty_Fail.Join (One) /= Slexy.Empty_Fail or
+ Nine.Join (Two) /= Ten
then
return Fail;
end if;
@@ -277,6 +286,21 @@ package body Ratnest.Tests is
end Join_Check;
+ function Equals_Check
+ return Test_Result
+ is
+ One : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Success, "abc");
+ Two : Slexy.Combinator_Result :=
+ Slexy.Create_Result (0, Packrat.Failure, "");
+ begin
+ if One = Two or Two /= Slexy.Empty_Fail then
+ return Fail;
+ end if;
+ return Pass;
+ end Equals_Check;
+
+
@@ -294,16 +318,19 @@ package body Ratnest.Tests is
Test_Str : String := "aababcabcab";
Result1 : Slexy.Combinator_Result :=
- Slexy.Create_Result (1, Packrat.Partial, "a");
+ Slexy.Create_Result (1, Packrat.Failure, "a");
Result2 : Slexy.Combinator_Result :=
- Slexy.Create_Result (2, Packrat.Partial, "ab");
+ Slexy.Create_Result (2, Packrat.Needs_More, "ab");
Result3 : Slexy.Combinator_Result :=
Slexy.Create_Result (3, Packrat.Success, "abc");
- Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result4 : Slexy.Combinator_Result := Slexy.Empty_Fail;
+ Result5 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Failure, "ab");
begin
- if Seq_Abc (Test_Str, 1) /= Result1 or Seq_Abc (Test_Str, 2) /= Result2 or
+ if Seq_Abc (Test_Str, 1) /= Result1 or Seq_Abc (Test_Str, 2) /= Result5 or
Seq_Abc (Test_Str, 4) /= Result3 or Seq_Abc (Test_Str, 10) /= Result2 or
- Seq_Abc (Test_Str, 3) /= Result4
+ Seq_Abc (Test_Str, 3) /= Result4 or
+ Seq_Abc (Test_Str, Test_Str'Last + 5) /= Result4
then
return Fail;
end if;
@@ -322,21 +349,22 @@ package body Ratnest.Tests is
Test_Str : String := "abaabbaaabbbaaaabbbb";
Result1 : Slexy.Combinator_Result :=
- Slexy.Create_Result (1, Packrat.Partial, "a");
+ Slexy.Create_Result (1, Packrat.Failure, "a");
Result2 : Slexy.Combinator_Result :=
Slexy.Create_Result (2, Packrat.Success, "aa");
Result3 : Slexy.Combinator_Result :=
- Slexy.Create_Result (1, Packrat.Partial, "b");
+ Slexy.Create_Result (1, Packrat.Failure, "b");
Result4 : Slexy.Combinator_Result :=
- Slexy.Create_Result (2, Packrat.Partial, "bb");
+ Slexy.Create_Result (2, Packrat.Needs_More, "bb");
Result5 : Slexy.Combinator_Result :=
Slexy.Create_Result (3, Packrat.Success, "bbb");
- Result6 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result6 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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, 2) /= Result3 or Count_3B (Test_Str, 19) /= 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
+ Count_2A (Test_Str, 2) /= Result6 or
+ Count_2A (Test_Str, Test_Str'Last + 5) /= Result6
then
return Fail;
end if;
@@ -351,18 +379,24 @@ package body Ratnest.Tests is
function Many_0 is new Strombo.Many (Match_A);
function Many_4 is new Strombo.Many (Match_A, 4);
- Test_Str : String := "aaabbaaaaab";
+ Test_Str : String := "aaabbaaaaabaa";
Result1 : Slexy.Combinator_Result :=
Slexy.Create_Result (3, Packrat.Success, "aaa");
Result2 : Slexy.Combinator_Result :=
- Slexy.Create_Result (3, Packrat.Partial, "aaa");
+ Slexy.Create_Result (2, Packrat.Optional_More, "aa");
Result3 : Slexy.Combinator_Result :=
Slexy.Create_Result (5, Packrat.Success, "aaaaa");
- Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Failure, "aaa");
+ Result5 : Slexy.Combinator_Result := Slexy.Empty_Fail;
+ Result6 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Needs_More, "aa");
begin
- 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
+ if Many_0 (Test_Str, 1) /= Result1 or Many_4 (Test_Str, 1) /= Result4 or
+ Many_4 (Test_Str, 6) /= Result3 or Many_0 (Test_Str, 4) /= Result5 or
+ Many_0 (Test_Str, 12) /= Result2 or Many_4 (Test_Str, 12) /= Result6 or
+ Many_0 (Test_Str, Test_Str'Last + 5) /= Result5
then
return Fail;
end if;
@@ -377,23 +411,23 @@ package body Ratnest.Tests is
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";
+ Test_Str : String := "aaaabbaaa123aaa";
Result1 : Slexy.Combinator_Result :=
- Slexy.Create_Result (4, Packrat.Partial, "aaaa");
+ Slexy.Create_Result (4, Packrat.Failure, "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;
+ Result3 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Optional_More, "aaa");
+ Result4 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ Many_Until_3 (Test_Str, 7) /= Result2 or
+ Many_Until_3 (Test_Str, 13) /= Result3 or
+ Many_Until_0 (Test_Str, 5) /= Result4 or
+ Many_Until_0 (Test_Str, Test_Str'Last + 5) /= Result4 or
+ Many_Until_3 (Test_Str, Test_Str'Last + 5) /= Result4
then
return Fail;
end if;
@@ -426,11 +460,12 @@ package body Ratnest.Tests is
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;
+ Result3 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
if Satisfy_123 (Test_Str, 6) /= Result2 or
Satisfy_Abc (Test_Str, 2) /= Result1 or
- Satisfy_Abc (Test_Str, 8) /= Result3
+ Satisfy_Abc (Test_Str, 8) /= Result3 or
+ Satisfy_123 (Test_Str, Test_Str'Last + 5) /= Result3
then
return Fail;
end if;
@@ -469,11 +504,12 @@ package body Ratnest.Tests is
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;
+ Result3 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
if Satisfy_Bcd (Test_Str, 3) /= Result1 or
Satisfy_234 (Test_Str, 7) /= Result2 or
- Satisfy_Bcd (Test_Str, 1) /= Result3
+ Satisfy_Bcd (Test_Str, 1) /= Result3 or
+ Satisfy_234 (Test_Str, Test_Str'Last + 5) /= Result3
then
return Fail;
end if;
@@ -496,12 +532,13 @@ package body Ratnest.Tests is
Slexy.Create_Result (1, Packrat.Success, "/");
Result3 : Slexy.Combinator_Result :=
Slexy.Create_Result (1, Packrat.Success, "4");
- Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result4 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ Match_A (Test_Str, 3) /= Result4 or
+ Match_A (Test_Str, Test_Str'Last + 5) /= Result4
then
return Fail;
end if;
@@ -528,11 +565,12 @@ package body Ratnest.Tests is
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;
+ Result3 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
if Match_A (Test_Str, 1) /= Result1 or
Match_6 (Test_Str, 5) /= Result2 or
- Match_A (Test_Str, 2) /= Result3
+ Match_A (Test_Str, 2) /= Result3 or
+ Match_A (Test_Str, Test_Str'Last + 5) /= Result3
then
return Fail;
end if;
@@ -546,20 +584,24 @@ package body Ratnest.Tests is
function Match_String1 is new Strombo.Multimatch ("abc");
function Match_String2 is new Strombo.Multimatch ("hello");
- Test_Str : String := "abcdefabhelloworld";
+ Test_Str : String := "abcdefabhelloworldab";
Result1 : Slexy.Combinator_Result :=
Slexy.Create_Result (3, Packrat.Success, "abc");
Result2 : Slexy.Combinator_Result :=
- Slexy.Create_Result (2, Packrat.Partial, "ab");
+ Slexy.Create_Result (2, Packrat.Needs_More, "ab");
Result3 : Slexy.Combinator_Result :=
Slexy.Create_Result (5, Packrat.Success, "hello");
- Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result4 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (2, Packrat.Failure, "ab");
+ Result5 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
if Match_String1 (Test_Str, 1) /= Result1 or
- Match_String1 (Test_Str, 7) /= Result2 or
+ Match_String1 (Test_Str, 7) /= Result4 or
Match_String2 (Test_Str, 9) /= Result3 or
- Match_String2 (Test_Str, 3) /= Result4
+ Match_String2 (Test_Str, 3) /= Result5 or
+ Match_String1 (Test_Str, 19) /= Result2 or
+ Match_String1 (Test_Str, Test_Str'Last + 5) /= Result5
then
return Fail;
end if;
@@ -578,13 +620,14 @@ package body Ratnest.Tests is
Result1 : Slexy.Combinator_Result :=
Slexy.Create_Result (1, Packrat.Success, "b");
Result2 : Slexy.Combinator_Result :=
- Slexy.Create_Result (3, Packrat.Partial, "ghi");
+ Slexy.Create_Result (3, Packrat.Needs_More, "ghi");
Result3 : Slexy.Combinator_Result :=
Slexy.Create_Result (5, Packrat.Success, "cdefg");
- Result4 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result4 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ Take_5 (Test_Str, 3) /= Result3 or
+ Take_1 (Test_Str, Test_Str'Last + 5) /= Result4
then
return Fail;
end if;
@@ -597,6 +640,7 @@ package body Ratnest.Tests is
is
function Take_Letters is new Strombo.Take_While (PU.Is_Letter);
function Take_Punch is new Strombo.Take_While (PU.Is_Punctuation);
+ function Take_Digits is new Strombo.Take_While (PU.Is_Digit);
Test_Str : String := "abcde,./;'fghi[]=-^563";
@@ -608,13 +652,17 @@ package body Ratnest.Tests is
Slexy.Create_Result (5, Packrat.Success, ",./;'");
Result4 : Slexy.Combinator_Result :=
Slexy.Create_Result (3, Packrat.Success, "=-^");
- Result5 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result5 : Slexy.Combinator_Result := Slexy.Empty_Fail;
+ Result6 : Slexy.Combinator_Result :=
+ Slexy.Create_Result (3, Packrat.Optional_More, "563");
begin
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
+ Take_Letters (Test_Str, 7) /= Result5 or
+ Take_Punch (Test_Str, Test_Str'Last + 5) /= Result5 or
+ Take_Digits (Test_Str, 20) /= Result6
then
return Fail;
end if;
@@ -633,18 +681,19 @@ package body Ratnest.Tests is
Result1 : Slexy.Combinator_Result :=
Slexy.Create_Result (7, Packrat.Success, "de12345");
Result2 : Slexy.Combinator_Result :=
- Slexy.Create_Result (4, Packrat.Partial, "hi67");
+ Slexy.Create_Result (4, Packrat.Optional_More, "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;
+ Result5 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ Take_Till_Punch (Test_Str, 11) /= Result5 or
+ Take_Till_Punch (Test_Str, Test_Str'Last + 5) /= Result5
then
return Fail;
end if;
@@ -652,27 +701,6 @@ package body Ratnest.Tests is
end Take_Until_Check;
- function Line_Start_Check
- 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
- 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
@@ -682,13 +710,13 @@ package body Ratnest.Tests is
Test_Str : String := "abcd" & Latin.LF & "e";
Result1 : Slexy.Combinator_Result :=
- Slexy.Create_Result (1, Packrat.Success, "" & Latin.LF);
+ Slexy.Create_Result (1, Packrat.Success, (1 => Latin.LF));
Result2 : Slexy.Combinator_Result :=
Slexy.Create_Result (1, Packrat.Success, "c");
- Result3 : Slexy.Combinator_Result := Slexy.Fail_Result;
+ Result3 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ LF_End (Test_Str, Test_Str'Last + 5) /= Result3 or LF_End (Test_Str, 1) /= Result3
then
return Fail;
end if;
@@ -696,23 +724,6 @@ package body Ratnest.Tests is
end Line_End_Check;
- function Input_Start_Check
- return Test_Result
- is
- Test_Str : String := "abcde";
-
- Result1 : Slexy.Combinator_Result :=
- Slexy.Create_Result (0, Packrat.Success, "");
- begin
- 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
@@ -725,13 +736,11 @@ package body Ratnest.Tests is
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;
+ Result3 : Slexy.Combinator_Result := Slexy.Empty_Fail;
begin
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
+ C_End (Test_Str, 1) /= Result3 or E_End (Test_Str, Test_Str'Last + 5) /= Result3
then
return Fail;
end if;
diff --git a/test/ratnest-tests.ads b/test/ratnest-tests.ads
index 5610db5..9febd35 100644
--- a/test/ratnest-tests.ads
+++ b/test/ratnest-tests.ads
@@ -48,6 +48,7 @@ package Ratnest.Tests is
package Lexer is
function Join_Check return Test_Result;
+ function Equals_Check return Test_Result;
function Sequence_Check return Test_Result;
function Count_Check return Test_Result;
@@ -63,13 +64,12 @@ package Ratnest.Tests is
function Take_While_Check return Test_Result;
function Take_Until_Check return Test_Result;
- function Line_Start_Check return Test_Result;
function Line_End_Check return Test_Result;
- function Input_Start_Check return Test_Result;
function Input_End_Check return Test_Result;
Combinator_Tests : Test_Array :=
((+"Join", Join_Check'Access),
+ (+"Equals", Equals_Check'Access),
(+"Sequence", Sequence_Check'Access),
(+"Count", Count_Check'Access),
(+"Many", Many_Check'Access),
@@ -82,9 +82,7 @@ package Ratnest.Tests is
(+"Take", Take_Check'Access),
(+"Take While", Take_While_Check'Access),
(+"Take Until", Take_Until_Check'Access),
- (+"Line Start", Line_Start_Check'Access),
(+"Line End", Line_End_Check'Access),
- (+"Input Start", Input_Start_Check'Access),
(+"Input_End", Input_End_Check'Access));
end Lexer;