From 192172cfc44220975b34295d38c5213b08de5191 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 10 Dec 2020 23:22:19 +1100 Subject: Some unit tests for Packrat.Parsers --- test/rat_tests-parsers.adb | 736 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 736 insertions(+) create mode 100644 test/rat_tests-parsers.adb (limited to 'test/rat_tests-parsers.adb') diff --git a/test/rat_tests-parsers.adb b/test/rat_tests-parsers.adb new file mode 100644 index 0000000..9368d6d --- /dev/null +++ b/test/rat_tests-parsers.adb @@ -0,0 +1,736 @@ + + +with + + Ada.Text_IO, + Packrat.Utilities; + + +package body Rat_Tests.Parsers is + + + use type Packrat.Result_Status; + + + + + + function Alphanum_Switch + (Char : in Character) + return Character is + begin + case Char is + when 'a' .. 'z' => + return Character'Val (48 + (Character'Pos (Char) - 97) mod 10); + when 'A' .. 'Z' => + return Character'Val (48 + (Character'Pos (Char) - 65) mod 10); + when '0' .. '9' => + return Character'Val (49 + (Character'Pos (Char))); + when others => + return Char; + end case; + end Alphanum_Switch; + + + + + + function Count_Check + return Test_Result + is + Input : String := "aaaa12aa"; + Context1, Context2, Context3, Context4 : Pone.Parsers.Parser_Context := + One_Debug.Empty_Context; + function Match_A is new Pone.Parsers.Match ('a'); + function Three_A is new Pone.Parsers.Count (Match_A, 3); + Result1 : Pone.Parsers.Combinator_Result := Three_A (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Three_A (Input, Context2, 3); + Result3 : Pone.Parsers.Combinator_Result := Three_A (Input, Context3, 5); + Result4 : Pone.Parsers.Combinator_Result := Three_A (Input, Context4, 7); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Failure or + One_Debug.Status (Result4) /= Packrat.Needs_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + begin + if Result1_Parts'Length /= 1 or + One_Debug.Parts (Result2)'Length /= 0 or + One_Debug.Parts (Result3)'Length /= 0 or + One_Debug.Parts (Result4)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Value (Result1_Parts (1))'Length /= 3 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Count_Check; + + + function Many_Nomin_Check + return Test_Result + is + Input : String := "abcd123efghi"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Sat_Letter is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Letter); + function Many_Letter is new Pone.Parsers.Many (Sat_Letter, 0); + Result1 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context2, 5); + Result3 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context3, 8); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Optional_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 5 or + Result2_Parts'Length /= 1 or + Result3_Parts'Length /= 6 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 0 or + One_Debug.Finish (Result1_Parts (2)) /= 1 or + One_Debug.Finish (Result1_Parts (3)) /= 2 or + One_Debug.Finish (Result1_Parts (4)) /= 3 or + One_Debug.Finish (Result1_Parts (5)) /= 4 + then + return Fail; + end if; + if One_Debug.Value (Result1_Parts (1))'Length /= 0 or + One_Debug.Value (Result1_Parts (2))'Length /= 1 or + One_Debug.Value (Result1_Parts (3))'Length /= 2 or + One_Debug.Value (Result1_Parts (4))'Length /= 3 or + One_Debug.Value (Result1_Parts (5))'Length /= 4 + then + return Fail; + end if; + if (for some P of Result1_Parts => One_Debug.Tokens (P)'Length /= 0) then + return Fail; + end if; + if One_Debug.Finish (Result2_Parts (1)) /= 4 or + One_Debug.Value (Result2_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result3_Parts (1)) /= 7 or + One_Debug.Finish (Result3_Parts (2)) /= 8 or + One_Debug.Finish (Result3_Parts (3)) /= 9 or + One_Debug.Finish (Result3_Parts (4)) /= 10 or + One_Debug.Finish (Result3_Parts (5)) /= 11 or + One_Debug.Finish (Result3_Parts (6)) /= 12 + then + return Fail; + end if; + if One_Debug.Value (Result3_Parts (1))'Length /= 0 or + One_Debug.Value (Result3_Parts (2))'Length /= 1 or + One_Debug.Value (Result3_Parts (3))'Length /= 2 or + One_Debug.Value (Result3_Parts (4))'Length /= 3 or + One_Debug.Value (Result3_Parts (5))'Length /= 4 or + One_Debug.Value (Result3_Parts (6))'Length /= 5 + then + return Fail; + end if; + if (for some P of Result3_Parts => One_Debug.Tokens (P)'Length /= 0) then + return Fail; + end if; + end; + return Pass; + end Many_Nomin_Check; + + + function Many_Min_Check + return Test_Result + is + Input : String := "abcd123efghi"; + Context1, Context2, Context3, Context4 : Pone.Parsers.Parser_Context := + One_Debug.Empty_Context; + function Sat_Letter is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Letter); + function Many_Letter is new Pone.Parsers.Many (Sat_Letter, 3); + Result1 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context2, 5); + Result3 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context3, 8); + Result4 : Pone.Parsers.Combinator_Result := Many_Letter (Input, Context4, 11); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Optional_More or + One_Debug.Status (Result4) /= Packrat.Needs_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 2 or + One_Debug.Parts (Result2)'Length /= 0 or + Result3_Parts'Length /= 3 or + One_Debug.Parts (Result4)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Finish (Result1_Parts (2)) /= 4 + then + return Fail; + end if; + if One_Debug.Value (Result1_Parts (1))'Length /= 3 or + One_Debug.Value (Result1_Parts (2))'Length /= 4 + then + return Fail; + end if; + if One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result1_Parts (2))'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result3_Parts (1)) /= 10 or + One_Debug.Finish (Result3_Parts (2)) /= 11 or + One_Debug.Finish (Result3_Parts (3)) /= 12 + then + return Fail; + end if; + if One_Debug.Value (Result3_Parts (1))'Length /= 3 or + One_Debug.Value (Result3_Parts (2))'Length /= 4 or + One_Debug.Value (Result3_Parts (3))'Length /= 5 + then + return Fail; + end if; + if One_Debug.Tokens (Result3_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result3_Parts (2))'Length /= 0 or + One_Debug.Tokens (Result3_Parts (3))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Many_Min_Check; + + + function Many_Until_Nomin_Check + return Test_Result + is + Input : String := "abc12de;fghi"; + Context1, Context2, Context3, Context4 : Pone.Parsers.Parser_Context := + One_Debug.Empty_Context; + function Sat_Letter is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Letter); + function Sat_Digit is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Digit); + function Body_Is_Dry is new Pone.Parsers.Many_Until (Sat_Letter, Sat_Digit, 0); + Result1 : Pone.Parsers.Combinator_Result := Body_Is_Dry (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Body_Is_Dry (Input, Context2, 4); + Result3 : Pone.Parsers.Combinator_Result := Body_Is_Dry (Input, Context3, 6); + Result4 : Pone.Parsers.Combinator_Result := Body_Is_Dry (Input, Context4, 9); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Failure or + One_Debug.Status (Result4) /= Packrat.Needs_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + begin + if Result1_Parts'Length /= 1 or + Result2_Parts'Length /= 1 or + One_Debug.Parts (Result3)'Length /= 0 or + One_Debug.Parts (Result4)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Value (Result1_Parts (1))'Length /= 3 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result2_Parts (1)) /= 3 or + One_Debug.Value (Result2_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Many_Until_Nomin_Check; + + + function Many_Until_Min_Check + return Test_Result + is + Input : String := "abcde12fgh"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Sat_Letter is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Letter); + function Sat_Digit is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Digit); + function Your_Way is new Pone.Parsers.Many_Until (Sat_Letter, Sat_Digit, 3); + Result1 : Pone.Parsers.Combinator_Result := Your_Way (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Your_Way (Input, Context2, 4); + Result3 : Pone.Parsers.Combinator_Result := Your_Way (Input, Context3, 8); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Needs_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + begin + if Result1_Parts'Length /= 1 or + One_Debug.Parts (Result2)'Length /= 0 or + One_Debug.Parts (Result3)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 5 or + One_Debug.Value (Result1_Parts (1))'Length /= 5 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Many_Until_Min_Check; + + + function Satisfy_Check + return Test_Result + is + Input : String := "abc123def"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Satisfy_Letter is new Pone.Parsers.Satisfy (Packrat.Utilities.Is_Letter); + Result1 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context1, 2); + Result2 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context2, 6); + Result3 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context3, 10); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Failure + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 1 or + Result2_Parts'Length /= 0 or + Result3_Parts'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 2 or + One_Debug.Value (Result1_Parts (1))'Length /= 1 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Satisfy_Check; + + + function Satisfy_With_Check + return Test_Result + is + Input : String := "abc123def"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Satisfy_Letter is new Pone.Parsers.Satisfy_With + (Packrat.Utilities.Is_Letter, Alphanum_Switch); + Result1 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context1, 2); + Result2 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context2, 6); + Result3 : Pone.Parsers.Combinator_Result := Satisfy_Letter (Input, Context3, 10); + begin + if One_Debug.Status (Result1) /= Packrat.Failure or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Failure + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 0 or + Result2_Parts'Length /= 1 or + Result3_Parts'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result2_Parts (1)) /= 6 or + One_Debug.Value (Result2_Parts (1))'Length /= 1 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Satisfy_With_Check; + + + function Match_Check + return Test_Result + is + Input : String := "aaabbbccc"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Match_B is new Pone.Parsers.Match ('b'); + Result1 : Pone.Parsers.Combinator_Result := Match_B (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Match_B (Input, Context2, 5); + Result3 : Pone.Parsers.Combinator_Result := Match_B (Input, Context3, 200); + begin + if One_Debug.Status (Result1) /= Packrat.Failure or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Failure + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 0 or + Result2_Parts'Length /= 1 or + Result3_Parts'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result2_Parts (1)) /= 5 or + One_Debug.Value (Result2_Parts (1))'Length /= 1 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Match_Check; + + + function Match_With_Check + return Test_Result + is + Input : String := "aaa111b2"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Match_0 is new Pone.Parsers.Match_With ('0', Alphanum_Switch); + Result1 : Pone.Parsers.Combinator_Result := Match_0 (Input, Context1, 3); + Result2 : Pone.Parsers.Combinator_Result := Match_0 (Input, Context2, 4); + Result3 : Pone.Parsers.Combinator_Result := Match_0 (Input, Context3, 7); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Failure + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 1 or + Result2_Parts'Length /= 0 or + Result3_Parts'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Value (Result1_Parts (1))'Length /= 1 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Match_With_Check; + + + function Multimatch_Check + return Test_Result + is + Input : String := "abcdefghi"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Multi is new Pone.Parsers.Multimatch ("def"); + Result1 : Pone.Parsers.Combinator_Result := Multi (Input, Context1, 2); + Result2 : Pone.Parsers.Combinator_Result := Multi (Input, Context2, 4); + Result3 : Pone.Parsers.Combinator_Result := Multi (Input, Context3, 300); + begin + if One_Debug.Status (Result1) /= Packrat.Failure or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Failure + then + return Fail; + end if; + declare + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + begin + if One_Debug.Parts (Result1)'Length /= 0 or + Result2_Parts'Length /= 1 or + One_Debug.Parts (Result3)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result2_Parts (1)) /= 6 or + One_Debug.Value (Result2_Parts (1))'Length /= 3 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Multimatch_Check; + + + function Take_Check + return Test_Result + is + Input : String := "abcdefghi"; + Context1, Context2, Context3, Context4 : Pone.Parsers.Parser_Context := + One_Debug.Empty_Context; + function Take_2 is new Pone.Parsers.Take (2); + function Take_5 is new Pone.Parsers.Take (5); + Result1 : Pone.Parsers.Combinator_Result := Take_2 (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Take_5 (Input, Context2, 3); + Result3 : Pone.Parsers.Combinator_Result := Take_5 (Input, Context3, 7); + Result4 : Pone.Parsers.Combinator_Result := Take_2 (Input, Context4, 100); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Needs_More or + One_Debug.Status (Result4) /= Packrat.Failure + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + begin + if Result1_Parts'Length /= 1 or + Result2_Parts'Length /= 1 or + One_Debug.Parts (Result3)'Length /= 0 or + One_Debug.Parts (Result4)'Length /= 0 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 2 or + One_Debug.Value (Result1_Parts (1))'Length /= 2 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Finish (Result2_Parts (1)) /= 7 or + One_Debug.Value (Result2_Parts (1))'Length /= 5 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Take_Check; + + + function Take_While_Check + return Test_Result + is + Input : String := "abc123def"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Take_On_Me is new Pone.Parsers.Take_While (Packrat.Utilities.Is_Letter); + Result1 : Pone.Parsers.Combinator_Result := Take_On_Me (Input, Context1, 2); + Result2 : Pone.Parsers.Combinator_Result := Take_On_Me (Input, Context2, 4); + Result3 : Pone.Parsers.Combinator_Result := Take_On_Me (Input, Context3, 7); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Optional_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 1 or + One_Debug.Parts (Result2)'Length /= 0 or + Result3_Parts'Length /= 1 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Value (Result1_Parts (1))'Length /= 2 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Finish (Result3_Parts (1)) /= 9 or + One_Debug.Value (Result3_Parts (1))'Length /= 3 or + One_Debug.Tokens (Result3_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Take_While_Check; + + + function Take_Until_Check + return Test_Result + is + Input : String := "abc123def"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Take_Me_On is new Pone.Parsers.Take_Until (Packrat.Utilities.Is_Digit); + Result1 : Pone.Parsers.Combinator_Result := Take_Me_On (Input, Context1, 2); + Result2 : Pone.Parsers.Combinator_Result := Take_Me_On (Input, Context2, 6); + Result3 : Pone.Parsers.Combinator_Result := Take_Me_On (Input, Context3, 8); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Failure or + One_Debug.Status (Result3) /= Packrat.Optional_More + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 1 or + One_Debug.Parts (Result2)'Length /= 0 or + Result3_Parts'Length /= 1 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 3 or + One_Debug.Value (Result1_Parts (1))'Length /= 2 or + One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Finish (Result3_Parts (1)) /= 9 or + One_Debug.Value (Result3_Parts (1))'Length /= 2 or + One_Debug.Tokens (Result3_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Take_Until_Check; + + + function Empty_Check + return Test_Result + is + Input : String := "abcdef"; + Context1, Context2, Context3 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + Result1 : Pone.Parsers.Combinator_Result := Pone.Parsers.Empty (Input, Context1, 1); + Result2 : Pone.Parsers.Combinator_Result := Pone.Parsers.Empty (Input, Context2, 3); + Result3 : Pone.Parsers.Combinator_Result := Pone.Parsers.Empty (Input, Context3, 10); + begin + if One_Debug.Status (Result1) /= Packrat.Success or + One_Debug.Status (Result2) /= Packrat.Success or + One_Debug.Status (Result3) /= Packrat.Success + then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + Result2_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result2); + Result3_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result3); + begin + if Result1_Parts'Length /= 1 or + Result2_Parts'Length /= 1 or + Result3_Parts'Length /= 1 + then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 0 or + One_Debug.Finish (Result2_Parts (1)) /= 2 or + One_Debug.Finish (Result3_Parts (1)) /= 9 + then + return Fail; + end if; + if One_Debug.Value (Result1_Parts (1))'Length /= 0 or + One_Debug.Value (Result2_Parts (1))'Length /= 0 or + One_Debug.Value (Result3_Parts (1))'Length /= 0 + then + return Fail; + end if; + if One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result2_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result3_Parts (1))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Empty_Check; + + + function Not_Empty_Check + return Test_Result + is + Input : String := "aa"; + Context1 : Pone.Parsers.Parser_Context := One_Debug.Empty_Context; + function Match_A is new Pone.Parsers.Match ('a'); + function Many_A is new Pone.Parsers.Many (Match_A, 0); + function NE_Many_A is new Pone.Parsers.Not_Empty (Many_A); + Result1 : Pone.Parsers.Combinator_Result := NE_Many_A (Input, Context1, 1); + begin + if One_Debug.Status (Result1) /= Packrat.Optional_More then + return Fail; + end if; + declare + Result1_Parts : One_Debug.Result_Part_Array := One_Debug.Parts (Result1); + begin + if Result1_Parts'Length /= 2 then + return Fail; + end if; + if One_Debug.Finish (Result1_Parts (1)) /= 1 or + One_Debug.Finish (Result1_Parts (2)) /= 2 + then + return Fail; + end if; + if One_Debug.Value (Result1_Parts (1))'Length /= 1 or + One_Debug.Value (Result1_Parts (2))'Length /= 2 + then + return Fail; + end if; + if One_Debug.Tokens (Result1_Parts (1))'Length /= 0 or + One_Debug.Tokens (Result1_Parts (2))'Length /= 0 + then + return Fail; + end if; + end; + return Pass; + end Not_Empty_Check; + + + + + + function Default_Result_Check + return Test_Result + is + Default : Pone.Parsers.Combinator_Result; + begin + if One_Debug.Status (Default) /= Packrat.Failure or + One_Debug.Parts (Default)'Length /= 0 or + not One_Debug.Is_Empty (One_Debug.Curtails (Default)) + then + return Fail; + end if; + return Pass; + end Default_Result_Check; + + +end Rat_Tests.Parsers; + + -- cgit