Natools

Check-in [ba3f2acfaa]
Login
Overview
Comment:s_expressions-parsers-tests: new test for Parser direct interface
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ba3f2acfaae5d16c9d68d5de6232e644d9b81872
User & Date: nat on 2014-01-22 22:26:19
Other Links: manifest | tags
Context
2014-01-23
22:17
s_expressions-parsers-tests: new test for Subparser interface check-in: d02a180cc6 user: nat tags: trunk
2014-01-22
22:26
s_expressions-parsers-tests: new test for Parser direct interface check-in: ba3f2acfaa user: nat tags: trunk
2014-01-21
20:16
s_expressions-parsers: fix parsing of nested subexpressions check-in: edac345527 user: nat tags: trunk
Changes

Modified tests/natools-s_expressions-parsers-tests.adb from [b6f39ca126] to [2330c6e453].

117
118
119
120
121
122
123

124
125
126
127
128
129
130
      Canonical_Encoding (Report);
      Atom_Encodings (Report);
      Base64_Subexpression (Report);
      Special_Subexpression (Report);
      Nested_Subpexression (Report);
      Number_Prefixes (Report);
      Quoted_Escapes (Report);

   end All_Tests;



   -----------------------
   -- Inidividual Tests --
   -----------------------







>







117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
      Canonical_Encoding (Report);
      Atom_Encodings (Report);
      Base64_Subexpression (Report);
      Special_Subexpression (Report);
      Nested_Subpexression (Report);
      Number_Prefixes (Report);
      Quoted_Escapes (Report);
      Parser_Interface (Report);
   end All_Tests;



   -----------------------
   -- Inidividual Tests --
   -----------------------
197
198
199
200
201
202
203







































































































































































204
205
206
207
208
209
210
           & "(5:valid6:quoted11:hexadecimal7:base-647:expr-64)"
           & "(9:undefined2:423:10%3:123()2:10)"
           & "(7:invalid6:quoted11:hexadecimal7:base-647:expr-64)"));
   begin
      Test (Report);
   end Number_Prefixes;









































































































































































   procedure Quoted_Escapes (Report : in out NT.Reporter'Class) is
      CR : constant Character := Character'Val (13);
      LF : constant Character := Character'Val (10);

      procedure Test is new Blackbox_Test
        (Name => "Escapes in quoted encoding",







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
           & "(5:valid6:quoted11:hexadecimal7:base-647:expr-64)"
           & "(9:undefined2:423:10%3:123()2:10)"
           & "(7:invalid6:quoted11:hexadecimal7:base-647:expr-64)"));
   begin
      Test (Report);
   end Number_Prefixes;


   procedure Parser_Interface (Report : in out NT.Reporter'Class) is
      Name : constant String := "Parser interface";
      Source : constant Atom
        := To_Atom ("(5:first6:second)");
   begin
      declare
         Input : aliased Test_Tools.Memory_Stream;
         Parser : Parsers.Parser;
      begin
         Input.Set_Data (Source);

         Parser.Next_Event (Input'Access);

         if Parser.Current_Event /= Events.Open_List then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current event "
              & Events.Event'Image (Parser.Current_Event));
            return;
         end if;

         if Parser.Current_Level /= 1 then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current level"
              & Integer'Image (Parser.Current_Level));
            return;
         end if;

         Parser.Next_Event (Input'Access);

         if Parser.Current_Event /= Events.Add_Atom then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current event "
              & Events.Event'Image (Parser.Current_Event));
            return;
         end if;

         if Parser.Current_Atom /= To_Atom ("first") then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current atom"
              & Integer'Image (Parser.Current_Atom'Length)
              & ":"
              & To_String (Parser.Current_Atom));
            return;
         end if;

         Parser.Next_Event (Input'Access);

         if Parser.Current_Event /= Events.Add_Atom then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current event "
              & Events.Event'Image (Parser.Current_Event));
            return;
         end if;

         declare
            Buffer : Atom (50 .. 69);
            Length : Count;
         begin
            Parser.Read_Atom (Buffer, Length);
            if Length /= 6
              or else Buffer (Buffer'First .. Buffer'First + Length - 1)
                        /= To_Atom ("second")
            then
               Report.Item (Name, NT.Fail);
               Report.Info ("Unexpected read atom"
                 & Count'Image (Length)
                 & ":"
                 & To_String (Buffer
                     (Buffer'First .. Buffer'First + Length - 1)));
               return;
            end if;
         end;

         declare
            Buffer : Atom (11 .. 13);
            Length : Count;
         begin
            Parser.Read_Atom (Buffer, Length);
            if Length /= 6
              or else Buffer /= To_Atom ("sec")
            then
               Report.Item (Name, NT.Fail);
               Report.Info ("Unexpected read atom"
                 & Count'Image (Length)
                 & ":"
                 & To_String (Buffer));
               return;
            end if;
         end;

         Parser.Next_Event (Input'Access);

         if Parser.Current_Event /= Events.Close_List then
            Report.Item (Name, NT.Fail);
            Report.Info ("Unexpected current event "
              & Events.Event'Image (Parser.Current_Event));
            return;
         end if;

         begin
            declare
               Result : constant Atom := Parser.Current_Atom;
            begin
               Report.Item (Name, NT.Fail);
               Report.Info
                 ("Current_Atom raised no exception and returned"
                  & Integer'Image (Result'Length)
                  & ':'
                  & To_String (Result));
            end;
         exception
            when Program_Error => null;
            when Error : others =>
               Report.Report_Exception (Name & " (in Current_Event)", Error);
         end;

         declare
            Buffer : Atom (1 .. 10);
            Length : Count;
         begin
            Parser.Read_Atom (Buffer, Length);
            Report.Item (Name, NT.Fail);
            Report.Info
              ("Read_Atom raised no exception and returned"
               & Count'Image (Length)
               & ':'
               & To_String (Buffer));
         exception
            when Program_Error => null;
            when Error : others =>
               Report.Report_Exception (Name & " (in Read_Atom)", Error);
         end;

         declare
            Called : Boolean := False;
            Output : Test_Tools.Memory_Stream;

            procedure Process (Data : in Atom);

            procedure Process (Data : in Atom) is
            begin
               Called := True;
               Output.Set_Data (Data);
            end Process;
         begin
            Parser.Query_Atom (Process'Access);
            Report.Item (Name, NT.Fail);
            Report.Info ("Query_Atom raised no exception");
            if Called then
               Report.Info ("   Process was called with atom """
                 & To_String (Output.Get_Data) & '"');
            end if;
         exception
            when Program_Error => null;
            when Error : others =>
               Report.Report_Exception (Name & " (in Query_Event)", Error);
               if Called then
                  Report.Info ("   Process was called with atom """
                    & To_String (Output.Get_Data) & '"');
               end if;
         end;
      end;
   exception
      when Error : others => Report.Report_Exception (Name, Error);
   end Parser_Interface;


   procedure Quoted_Escapes (Report : in out NT.Reporter'Class) is
      CR : constant Character := Character'Val (13);
      LF : constant Character := Character'Val (10);

      procedure Test is new Blackbox_Test
        (Name => "Escapes in quoted encoding",

Modified tests/natools-s_expressions-parsers-tests.ads from [f7cc36cf63] to [014bfd3a14].

29
30
31
32
33
34
35

36
37
38
39
   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Atom_Encodings (Report : in out NT.Reporter'Class);
   procedure Base64_Subexpression (Report : in out NT.Reporter'Class);
   procedure Canonical_Encoding (Report : in out NT.Reporter'Class);
   procedure Nested_Subpexression (Report : in out NT.Reporter'Class);
   procedure Number_Prefixes (Report : in out NT.Reporter'Class);

   procedure Quoted_Escapes (Report : in out NT.Reporter'Class);
   procedure Special_Subexpression (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Parsers.Tests;







>




29
30
31
32
33
34
35
36
37
38
39
40
   procedure All_Tests (Report : in out NT.Reporter'Class);

   procedure Atom_Encodings (Report : in out NT.Reporter'Class);
   procedure Base64_Subexpression (Report : in out NT.Reporter'Class);
   procedure Canonical_Encoding (Report : in out NT.Reporter'Class);
   procedure Nested_Subpexression (Report : in out NT.Reporter'Class);
   procedure Number_Prefixes (Report : in out NT.Reporter'Class);
   procedure Parser_Interface (Report : in out NT.Reporter'Class);
   procedure Quoted_Escapes (Report : in out NT.Reporter'Class);
   procedure Special_Subexpression (Report : in out NT.Reporter'Class);

end Natools.S_Expressions.Parsers.Tests;