summaryrefslogtreecommitdiff
path: root/test/rat_tests-errors.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-05-24 19:07:23 +1000
committerJed Barber <jjbarber@y7mail.com>2020-05-24 19:07:23 +1000
commit731e861f233ab90078c00b3dad5ace4eaed45e95 (patch)
tree173ac51104a31864a073e6c5c140853aee1ed80e /test/rat_tests-errors.adb
parent94609aeabcd441caa7c9d41f54166b3f3ede1442 (diff)
Revamped tests to use the basic-unit-test project
Diffstat (limited to 'test/rat_tests-errors.adb')
-rw-r--r--test/rat_tests-errors.adb169
1 files changed, 169 insertions, 0 deletions
diff --git a/test/rat_tests-errors.adb b/test/rat_tests-errors.adb
new file mode 100644
index 0000000..75d2c34
--- /dev/null
+++ b/test/rat_tests-errors.adb
@@ -0,0 +1,169 @@
+
+
+with Packrat;
+
+
+package body Rat_Tests.Errors is
+
+
+ package PE renames Packrat.Errors;
+
+
+
+
+
+ function Valid_Message_Check
+ return Test_Result is
+ begin
+ if PE.Valid_Message ("abcde") or PE.Valid_Message ("sSYM") or
+ PE.Valid_Message ("sSYMp") or PE.Valid_Message ("p345") or
+ PE.Valid_Message ("pOne") or PE.Valid_Message ("sSYMp1sNEXT") or
+ PE.Valid_Message ("sSYMp1.2") or PE.Valid_Message ("sABcDp12") or
+ not PE.Valid_Message ("sSYMp0") or not PE.Valid_Message ("sAp12") or
+ 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 Fail;
+ end if;
+ return Pass;
+ end Valid_Message_Check;
+
+
+
+
+
+ function Valid_Identifier_Check
+ return Test_Result
+ is
+ Pass_Array : PE.Error_Info_Array :=
+ ((+"A", 1), (+"ABC", 2), (+"AB_CD", 3), (+"A_B_CD", 4));
+ Fail_Array : PE.Error_Info_Array :=
+ ((+"_", 1), (+"_A", 2), (+"A_", 3), (+"A__B", 4), (+"A%B", 3));
+ begin
+ for EI of Pass_Array loop
+ if not PE.Valid_Identifier (EI.Symbol) or
+ not PE.Valid_Identifier (-EI.Symbol)
+ then
+ 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 Fail;
+ end if;
+ end loop;
+ if not PE.Valid_Identifier_Array (Pass_Array) or
+ PE.Valid_Identifier_Array (Fail_Array)
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Valid_Identifier_Check;
+
+
+
+
+
+ function Join_Check
+ return Test_Result
+ is
+ Array_1 : PE.Error_Info_Array := ((+"A", 1), (+"B", 2));
+ Msg_1 : PE.Error_Message := PE.Encode_Array (Array_1);
+
+ Array_2 : PE.Error_Info_Array := ((+"C", 3), (+"D", 4));
+ Msg_2 : PE.Error_Message := PE.Encode_Array (Array_2);
+
+ Msg_3 : PE.Error_Message := PE.Join (Msg_1, Msg_2);
+
+ Array_4 : PE.Error_Info_Array := ((+"A", 1), (+"B", 2), (+"C", 3), (+"D", 4));
+ Msg_4 : PE.Error_Message := PE.Encode_Array (Array_4);
+
+ Array_5 : PE.Error_Info_Array := ((+"A", 1), (+"B", 4));
+ Msg_5 : PE.Error_Message := PE.Encode_Array (Array_5);
+
+ Array_6 : PE.Error_Info_Array := ((+"A", 1), (+"C", 3));
+ Msg_6 : PE.Error_Message := PE.Encode_Array (Array_6);
+
+ Msg_7 : PE.Error_Message := PE.Join (Msg_5, Msg_6);
+
+ Array_8 : PE.Error_Info_Array := ((+"A", 1), (+"B", 4), (+"C", 3));
+ Msg_8 : PE.Error_Message := PE.Encode_Array (Array_8);
+ begin
+ if Msg_3 /= Msg_4 or Msg_7 /= Msg_8 then
+ return Fail;
+ end if;
+ return Pass;
+ end Join_Check;
+
+
+
+
+
+ function Encode_1_Check
+ return Test_Result is
+ begin
+ -- Encode with a String and a Natural
+ if PE.Encode ("ABC", 15) /= "sABCp15" then
+ return Fail;
+ end if;
+ return Pass;
+ end Encode_1_Check;
+
+
+ function Encode_2_Check
+ return Test_Result is
+ begin
+ -- Encode with an Unbounded_String and a Natural
+ if PE.Encode (+"ABC", 15) /= "sABCp15" then
+ return Fail;
+ end if;
+ return Pass;
+ end Encode_2_Check;
+
+
+ function Encode_3_Check
+ return Test_Result is
+ begin
+ -- Encode with an Error_Info
+ if PE.Encode ((+"ABC", 15)) /= "sABCp15" then
+ return Fail;
+ end if;
+ return Pass;
+ end Encode_3_Check;
+
+
+ function Encode_4_Check
+ return Test_Result is
+ begin
+ -- Encode with an Error_Info_Array
+ if PE.Encode_Array (((+"A", 3), (+"BC", 2), (+"ABC", 1), (+"B", 4))) /=
+ "sAp3sBCp2sABCp1sBp4"
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Encode_4_Check;
+
+
+
+
+
+ function Decode_Check
+ return Test_Result
+ is
+ use type PE.Error_Info_Array;
+ begin
+ if PE.Decode ("sAp1sBp3sCp10sDEFp456") /=
+ ((+"A", 1), (+"B", 3), (+"C", 10), (+"DEF", 456))
+ then
+ return Fail;
+ end if;
+ return Pass;
+ end Decode_Check;
+
+
+end Rat_Tests.Errors;
+
+