summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2019-01-08 10:47:05 +1100
committerJed Barber <jjbarber@y7mail.com>2019-01-08 10:47:05 +1100
commit458d695b56779d707ae8689295f334b934d3e3f5 (patch)
treeef046073a1a1a15ecf096b5458dbf5dc9d5a94f0 /test
parentaeb7002796a51725e2478a751b21b4d4c3a56815 (diff)
Tests for Packrat.Util set predicates
Diffstat (limited to 'test')
-rw-r--r--test/ratnest-tests.adb116
-rw-r--r--test/ratnest-tests.ads14
-rw-r--r--test/test_main.adb3
3 files changed, 129 insertions, 4 deletions
diff --git a/test/ratnest-tests.adb b/test/ratnest-tests.adb
index 2479998..3309b2a 100644
--- a/test/ratnest-tests.adb
+++ b/test/ratnest-tests.adb
@@ -3,6 +3,7 @@
with
Ada.Characters.Latin_1,
+ Ada.Strings.Maps,
Packrat.Util;
@@ -10,11 +11,126 @@ package body Ratnest.Tests is
package Latin renames Ada.Characters.Latin_1;
+ package Strmaps renames Ada.Strings.Maps;
package PU renames Packrat.Util;
+
+ function In_Set_Check
+ return Test_Result
+ is
+ use type Strmaps.Character_Set;
+ Set_1 : Strmaps.Character_Set := Strmaps.To_Set ("abcxyz");
+ Set_2 : Strmaps.Character_Set := Strmaps.To_Set ("!""#$");
+ function Func_1 is new PU.In_Set (Set_1);
+ function Func_2 is new PU.In_Set (Set_2);
+ begin
+ -- 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;
+ end if;
+ end loop;
+ for C in Character range 'a' .. 'c' loop
+ if not Func_1 (C) then
+ return Failure;
+ 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;
+ end if;
+ end loop;
+ for C in Character range 'x' .. 'z' loop
+ if not Func_1 (C) then
+ return Failure;
+ 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;
+ 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;
+ end if;
+ end loop;
+ for C in Character range '!' .. '$' loop
+ if not Func_2 (C) then
+ return Failure;
+ 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;
+ end if;
+ end loop;
+ return Success;
+ end In_Set_Check;
+
+
+ function Not_In_Set_Check
+ return Test_Result
+ is
+ use type Strmaps.Character_Set;
+ Set_1 : Strmaps.Character_Set := Strmaps.To_Set ("abcxyz");
+ Set_2 : Strmaps.Character_Set := Strmaps.To_Set ("!""#$");
+ function Func_1 is new PU.Not_In_Set (Set_1);
+ function Func_2 is new PU.Not_In_Set (Set_2);
+ begin
+ -- 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;
+ end if;
+ end loop;
+ for C in Character range 'a' .. 'c' loop
+ if Func_1 (C) then
+ return Failure;
+ 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;
+ end if;
+ end loop;
+ for C in Character range 'x' .. 'z' loop
+ if Func_1 (C) then
+ return Failure;
+ 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;
+ 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;
+ end if;
+ end loop;
+ for C in Character range '!' .. '$' loop
+ if Func_2 (C) then
+ return Failure;
+ 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;
+ end if;
+ end loop;
+ return Success;
+ end Not_In_Set_Check;
+
+
+
+
+
function Is_Digit_Check
return Test_Result is
begin
diff --git a/test/ratnest-tests.ads b/test/ratnest-tests.ads
index c0be0a9..fdcbe71 100644
--- a/test/ratnest-tests.ads
+++ b/test/ratnest-tests.ads
@@ -3,6 +3,16 @@
package Ratnest.Tests is
+ function In_Set_Check return Test_Result;
+ function Not_In_Set_Check return Test_Result;
+
+ Set_Predicate_Tests : Test_Array :=
+ ((+"In_Set", In_Set_Check'Access),
+ (+"Not_In_Set", Not_In_Set_Check'Access));
+
+
+
+
function Is_Digit_Check return Test_Result;
function Is_Hex_Check return Test_Result;
function Is_Letter_Check return Test_Result;
@@ -16,7 +26,6 @@ package Ratnest.Tests is
function Is_Whitespace_Check return Test_Result;
function Not_Whitespace_Check return Test_Result;
-
Util_Predicate_Tests : Test_Array :=
((+"Is_Digit", Is_Digit_Check'Access),
(+"Is_Hex", Is_Hex_Check'Access),
@@ -32,9 +41,6 @@ package Ratnest.Tests is
(+"Not_Whitespace", Not_Whitespace_Check'Access));
-private
-
-
end Ratnest.Tests;
diff --git a/test/test_main.adb b/test/test_main.adb
index 417ae7d..3ab5269 100644
--- a/test/test_main.adb
+++ b/test/test_main.adb
@@ -15,6 +15,9 @@ use
procedure Test_Main is
begin
Put_Line ("Running tests for Packrat.Util...");
+ Put_Line ("Testing set predicates...");
+ Run_Tests (Set_Predicate_Tests);
+ Put_Line ("Testing ordinary predicates...");
Run_Tests (Util_Predicate_Tests);
end Test_Main;