summaryrefslogtreecommitdiff
path: root/test/rat_tests-errors.adb
blob: ee9500463d174e069643c9a2ec82320e174a10f0 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169


with Packrat.Errors;


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;