439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
|
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
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser current event: "
& Events.Event'Image (Event));
return;
end if;
if Sub.Current_Atom /= To_Atom ("arg1") then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report, Sub.Current_Atom,
"Unexpected first subparser atom");
return;
end if;
Sub.Next (Event);
if Event /= Events.Open_List then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser second event: "
& Events.Event'Image (Event));
return;
end if;
if Sub.Current_Level /= 3 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected nesting level"
& Natural'Image (Sub.Current_Level));
end if;
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser third event: "
& Events.Event'Image (Event));
return;
end if;
declare
Data : Atom (21 .. 40);
Length : Count;
begin
Sub.Read_Atom (Data, Length);
if Data (Data'First .. Data'First + Length - 1)
/= To_Atom ("subarg1")
then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report,
Data (Data'First .. Data'First + Length - 1),
"Unexpected first sub-argument atom:");
return;
end if;
end;
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser third event: "
& Events.Event'Image (Event));
return;
end if;
Sub.Finish;
-- Check final state of parser
if Parser.Current_Event /= Events.Close_List then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected parser final state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Parser.Current_Level /= 1 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected parser final level:"
& Natural'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 parser penultimate state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Parser.Current_Atom /= To_Atom ("end") then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report, Parser.Current_Atom,
"Parser last atom");
end if;
-- Check subparser error states
if Sub.Current_Event /= Events.End_Of_Input then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser final state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Sub.Current_Level /= 2 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser final level:"
& Natural'Image (Parser.Current_Level));
return;
end if;
begin
declare
Buffer : constant Atom := Sub.Current_Atom;
begin
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Current_Atom on finished subparser");
Test_Tools.Dump_Atom (Report, Buffer);
end;
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Current_Atom)", Error);
return;
end;
declare
Buffer : Atom (1 .. 100);
Length : Count := 0;
begin
Sub.Read_Atom (Buffer, Length);
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Read_Atom on finished subparser");
Test_Tools.Dump_Atom (Report, Buffer (1 .. Length));
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Read_Atom)", Error);
Test_Tools.Dump_Atom (Report, Buffer (1 .. Length), "Buffer");
return;
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
Sub.Query_Atom (Process'Access);
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Query_Atom on finished subparser");
if Called then
Test_Tools.Dump_Atom (Report, Output.Get_Data,
"Process called with");
end if;
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Query_Event)", Error);
if Called then
Test_Tools.Dump_Atom (Report, Output.Get_Data,
"Process called with");
end if;
return;
end;
begin
Sub.Next (Event);
Report.Item (Name, NT.Fail);
Report.Info ("No exception raised in Next on finished subparser");
Report.Info (" returned event: " & Events.Event'Image (Event));
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Next)", Error);
return;
end;
-- Check that above subparser calls have not tampered with Parser
if Parser.Current_Event /= Events.Add_Atom
or else Parser.Current_Level /= 1
or else Parser.Current_Atom /= To_Atom ("end")
then
Report.Item (Name, NT.Fail);
Report.Info ("Parser state changed after calling methods on "
& "finished subparser");
return;
end if;
end;
Report.Item (Name, NT.Success);
exception
when Error : others => Report.Report_Exception (Name, Error);
end Subparser_Interface;
end Natools.S_Expressions.Parsers.Tests;
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
|
<
|
|
<
|
<
<
|
<
|
<
|
|
|
|
<
|
|
>
|
|
<
|
<
|
>
|
<
<
|
|
<
|
|
<
|
<
<
|
|
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
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: "
& Events.Event'Image (Parser.Current_Event));
end if;
if Parser.Current_Level /= 1 then
Test.Fail ("Unexpected parser final level:"
& Natural'Image (Parser.Current_Level));
end if;
Parser.Next_Event (Input'Access);
if Parser.Current_Event /= Events.Add_Atom then
Test.Fail ("Unexpected parser penultimate state: "
& Events.Event'Image (Parser.Current_Event));
end if;
if Parser.Current_Atom /= To_Atom ("end") then
Test.Fail;
Test_Tools.Dump_Atom (Test, Parser.Current_Atom,
"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;
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
Sub.Query_Atom (Process'Access);
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;
end;
begin
Sub.Next (Event);
Test.Fail ("No exception raised in Next on finished subparser");
Test.Info (" returned event: " & Events.Event'Image (Event));
exception
when Constraint_Error => null;
when Error : others =>
Test.Report_Exception (Error);
Test.Info ("in Next");
end;
-- Check that above subparser calls have not tampered with Parser
if Parser.Current_Event /= Events.Add_Atom
or else Parser.Current_Level /= 1
or else Parser.Current_Atom /= To_Atom ("end")
then
Test.Fail ("Parser state changed after calling methods on "
& "finished subparser");
return;
end if;
end;
exception
when Error : others => Test.Report_Exception (Error);
end Subparser_Interface;
end Natools.S_Expressions.Parsers.Tests;
|