Natools

Diff
Login

Differences From Artifact [f6937be6c8]:

To Artifact [e5f07b4bc7]:


10
11
12
13
14
15
16

17
18
19
20
21
22
23
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------


with Natools.S_Expressions.Printers;
with Natools.S_Expressions.Test_Tools;

package body Natools.S_Expressions.Parsers.Tests is

   procedure Check_Parsing
     (Report : in out NT.Reporter'Class;







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Natools.S_Expressions.Lockable.Tests;
with Natools.S_Expressions.Printers;
with Natools.S_Expressions.Test_Tools;

package body Natools.S_Expressions.Parsers.Tests is

   procedure Check_Parsing
     (Report : in out NT.Reporter'Class;
119
120
121
122
123
124
125

126
127
128
129
130
131
132
      Base64_Subexpression (Report);
      Special_Subexpression (Report);
      Nested_Subpexression (Report);
      Number_Prefixes (Report);
      Quoted_Escapes (Report);
      Parser_Interface (Report);
      Subparser_Interface (Report);

   end All_Tests;



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







>







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
      Base64_Subexpression (Report);
      Special_Subexpression (Report);
      Nested_Subpexression (Report);
      Number_Prefixes (Report);
      Quoted_Escapes (Report);
      Parser_Interface (Report);
      Subparser_Interface (Report);
      Lockable_Interface (Report);
   end All_Tests;



   -----------------------
   -- Inidividual Tests --
   -----------------------
167
168
169
170
171
172
173

















174
175
176
177
178
179
180
        (Name => "Base-64 subexpression",
         Source => To_Atom ("head({KDc6c3VibGlzdCk1OnRva2Vu})""tail"""),
         Expected => To_Atom ("4:head((7:sublist)5:token)4:tail"));
   begin
      Test (Report);
   end Base64_Subexpression;



















   procedure Nested_Subpexression (Report : in out NT.Reporter'Class) is
      procedure Test is new Blackbox_Test
        (Name => "Nested base-64 subepxressions",
         Source => To_Atom ("(5:begin"
           & "{KG5lc3RlZCB7S0dSbFpYQWdjR0Y1Ykc5aFpDaz19KQ==}"
           & "end)"),







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







169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
        (Name => "Base-64 subexpression",
         Source => To_Atom ("head({KDc6c3VibGlzdCk1OnRva2Vu})""tail"""),
         Expected => To_Atom ("4:head((7:sublist)5:token)4:tail"));
   begin
      Test (Report);
   end Base64_Subexpression;


   procedure Lockable_Interface (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("Lockable.Descriptor interface");
   begin
      declare
         Input : aliased Test_Tools.Memory_Stream;
         Parser : aliased Parsers.Parser;
         Sub : Subparser (Parser'Access, Input'Access);
      begin
         Input.Set_Data (Lockable.Tests.Test_Expression);
         Test_Tools.Next_And_Check (Test, Sub, Events.Open_List, 1);
         Lockable.Tests.Test_Interface (Test, Sub);
      end;
   exception
      when Error : others => Test.Report_Exception (Error);
   end Lockable_Interface;


   procedure Nested_Subpexression (Report : in out NT.Reporter'Class) is
      procedure Test is new Blackbox_Test
        (Name => "Nested base-64 subepxressions",
         Source => To_Atom ("(5:begin"
           & "{KG5lc3RlZCB7S0dSbFpYQWdjR0Y1Ykc5aFpDaz19KQ==}"
           & "end)"),
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
         pragma Assert (Parser.Current_Event = Events.Open_List);
         Parser.Next_Event (Input'Access);
         pragma Assert (Parser.Current_Event = Events.Add_Atom
           and then Parser.Current_Atom = To_Atom ("command"));

         --  Use subparser as command arguments

         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("arg1"), 2);
         Test_Tools.Next_And_Check (Test, Sub, Events.Open_List, 3);
         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("subarg1"), 3);
         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("subarg2"), 3);

         Sub.Finish;

         --  Check final state of parser

         if Parser.Current_Event /= Events.Close_List then
            Test.Fail ("Unexpected parser final state: "







|
|
|
|







458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
         pragma Assert (Parser.Current_Event = Events.Open_List);
         Parser.Next_Event (Input'Access);
         pragma Assert (Parser.Current_Event = Events.Add_Atom
           and then Parser.Current_Atom = To_Atom ("command"));

         --  Use subparser as command arguments

         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("arg1"), 0);
         Test_Tools.Next_And_Check (Test, Sub, Events.Open_List, 1);
         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("subarg1"), 1);
         Test_Tools.Next_And_Check (Test, Sub, To_Atom ("subarg2"), 1);

         Sub.Finish;

         --  Check final state of parser

         if Parser.Current_Event /= Events.Close_List then
            Test.Fail ("Unexpected parser final state: "
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
              "Parser last atom");
         end if;

         --  Check subparser error states

         if Sub.Current_Event /= Events.End_Of_Input then
            Test.Fail ("Unexpected subparser final state: "
              & Events.Event'Image (Parser.Current_Event));
         end if;

         if Sub.Current_Level /= 2 then
            Test.Fail ("Unexpected subparser final level:"
              & Natural'Image (Parser.Current_Level));
         end if;

         begin
            declare
               Buffer : constant Atom := Sub.Current_Atom;
            begin
               Test.Fail
                 ("No exception raised in Current_Atom on finished subparser");
               Test_Tools.Dump_Atom (Test, Buffer);
            end;
            return;
         exception
            when Constraint_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Current_Atom");
         end;

         declare
            Buffer : Atom (1 .. 100);
            Length : Count := 0;
         begin
            Sub.Read_Atom (Buffer, Length);
            Test.Fail
              ("No exception raised in Read_Atom on finished subparser");
            Test_Tools.Dump_Atom (Test, Buffer (1 .. Length));
            return;
         exception
            when Constraint_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Read_Atom");
               Test_Tools.Dump_Atom (Test, Buffer (1 .. Length), "Buffer");
               return;
         end;








|


|

|












|















|







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
              "Parser last atom");
         end if;

         --  Check subparser error states

         if Sub.Current_Event /= Events.End_Of_Input then
            Test.Fail ("Unexpected subparser final state: "
              & Events.Event'Image (Sub.Current_Event));
         end if;

         if Sub.Current_Level /= 0 then
            Test.Fail ("Unexpected subparser final level:"
              & Natural'Image (Sub.Current_Level));
         end if;

         begin
            declare
               Buffer : constant Atom := Sub.Current_Atom;
            begin
               Test.Fail
                 ("No exception raised in Current_Atom on finished subparser");
               Test_Tools.Dump_Atom (Test, Buffer);
            end;
            return;
         exception
            when Program_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Current_Atom");
         end;

         declare
            Buffer : Atom (1 .. 100);
            Length : Count := 0;
         begin
            Sub.Read_Atom (Buffer, Length);
            Test.Fail
              ("No exception raised in Read_Atom on finished subparser");
            Test_Tools.Dump_Atom (Test, Buffer (1 .. Length));
            return;
         exception
            when Program_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Read_Atom");
               Test_Tools.Dump_Atom (Test, Buffer (1 .. Length), "Buffer");
               return;
         end;

537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
            Test.Fail
              ("No exception raised in Query_Atom on finished subparser");
            if Called then
               Test_Tools.Dump_Atom (Test, Output.Get_Data,
                 "Process called with");
            end if;
         exception
            when Constraint_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Query_Event");
               if Called then
                  Test_Tools.Dump_Atom (Test, Output.Get_Data,
                    "Process called with");
               end if;







|







556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
            Test.Fail
              ("No exception raised in Query_Atom on finished subparser");
            if Called then
               Test_Tools.Dump_Atom (Test, Output.Get_Data,
                 "Process called with");
            end if;
         exception
            when Program_Error => null;
            when Error : others =>
               Test.Report_Exception (Error);
               Test.Info ("in Query_Event");
               if Called then
                  Test_Tools.Dump_Atom (Test, Output.Get_Data,
                    "Process called with");
               end if;