1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 | with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with AUnit.Assertions; use AUnit.Assertions;
with Rejuvenation.Nested; use Rejuvenation.Nested;
package body Test_Nested is
OFF_TAG : constant String := "--@OFF@--";
ON_TAG : constant String := "--@ON@--";
procedure Test_None (T : in out Test_Case'Class);
procedure Test_None (T : in out Test_Case'Class) is
pragma Unreferenced (T);
Input : constant String := "Test";
begin
-- pre condition checks
Assert
(Condition => Index (Input, ON_TAG) = 0,
Message => "ON_TAG unexpectedly in input");
Assert
(Condition => Index (Input, OFF_TAG) = 0,
Message => "OFF_TAG unexpectedly in input");
-- test
Assert
(Actual => Remove_Nested_Flags (Input, ON_TAG, OFF_TAG),
Expected => Input,
Message =>
"Unexpected difference with input " &
"without any on/off flags - " & Input);
end Test_None;
procedure Test_Flat (T : in out Test_Case'Class);
procedure Test_Flat (T : in out Test_Case'Class) is
pragma Unreferenced (T);
Construction : Unbounded_String := To_Unbounded_String (OFF_TAG);
Occurances : constant Positive := 2;
begin
for Index in 1 .. Occurances loop
Append (Construction, Index'Image & ON_TAG & Index'Image & OFF_TAG);
end loop;
Append (Construction, "Tail");
declare
Input : constant String := To_String (Construction);
Actual : constant String :=
Remove_Nested_Flags (Input, ON_TAG, OFF_TAG, 1);
begin
Assert
(Actual => Actual, Expected => Input,
Message => "Unexpected difference with flat string - " & Input);
end;
end Test_Flat;
procedure Test_Nested (T : in out Test_Case'Class);
procedure Test_Nested (T : in out Test_Case'Class) is
pragma Unreferenced (T);
Construction_Input, Construction_Expected : Unbounded_String :=
To_Unbounded_String (OFF_TAG);
Depth : constant Positive := 2;
begin
Append (Construction_Input, "Head");
Append (Construction_Expected, "Head");
Append (Construction_Expected, ON_TAG);
for Index in 1 .. Depth loop
Append (Construction_Input, ON_TAG & Index'Image);
Append (Construction_Expected, Index'Image);
end loop;
for Index in reverse 1 .. Depth loop
Append (Construction_Input, Index'Image & OFF_TAG);
Append (Construction_Expected, Index'Image);
end loop;
Append (Construction_Expected, OFF_TAG);
Append (Construction_Input, "Tail");
Append (Construction_Expected, "Tail");
declare
Input : constant String := To_String (Construction_Input);
Expected : constant String := To_String (Construction_Expected);
Actual : constant String :=
Remove_Nested_Flags (Input, ON_TAG, OFF_TAG, 1);
begin
Assert
(Actual => Actual, Expected => Expected,
Message => "Unexpected difference with nested string - " & Input);
end;
end Test_Nested;
-- Test plumbing
overriding function Name (T : Nested_Test_Case) return AUnit.Message_String
is
pragma Unreferenced (T);
begin
return AUnit.Format ("Nested");
end Name;
overriding procedure Register_Tests (T : in out Nested_Test_Case) is
begin
Registration.Register_Routine (T, Test_None'Access, "None");
Registration.Register_Routine (T, Test_Flat'Access, "Flat");
Registration.Register_Routine (T, Test_Nested'Access, "Nested");
end Register_Tests;
end Test_Nested;
|