Overview
Comment: | s_expressions-parsers-tests: new test for Subparser interface |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
d02a180cc64438528cb8574c1c9e0cb1 |
User & Date: | nat on 2014-01-23 22:17:10 |
Other Links: | manifest | tags |
Context
2014-01-24
| ||
21:59 | tests: new interface using finalization to ensure reporting is correct in all code paths check-in: 444efe557e user: nat tags: trunk | |
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 | |
Changes
Modified tests/natools-s_expressions-parsers-tests.adb from [2330c6e453] to [ebc5db0049].
︙ | ︙ | |||
118 119 120 121 122 123 124 125 126 127 128 129 130 131 | 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 -- ----------------------- | > | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | Atom_Encodings (Report); 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 -- ----------------------- |
︙ | ︙ | |||
361 362 363 364 365 366 367 368 369 370 371 372 373 374 | 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); | > > | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | 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; Report.Item (Name, NT.Success); 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); |
︙ | ︙ | |||
407 408 409 410 411 412 413 414 | & "10:hidden-end)(12:hidden-begin" & "3:end)" & "(16:overflowing atom)")); begin Test (Report); end Special_Subexpression; end Natools.S_Expressions.Parsers.Tests; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 | & "10:hidden-end)(12:hidden-begin" & "3:end)" & "(16:overflowing atom)")); begin Test (Report); end Special_Subexpression; procedure Subparser_Interface (Report : in out NT.Reporter'Class) is Name : constant String := "Subparser interface"; Source : constant Atom := To_Atom ("(begin(command arg1 (subarg1 subarg2) arg3)end)"); begin declare Input : aliased Test_Tools.Memory_Stream; Parser : aliased Parsers.Parser; Sub : Subparser (Parser'Access, Input'Access); Event : Events.Event; begin Input.Set_Data (Source); -- Read header Parser.Next_Event (Input'Access); 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 ("begin")); Parser.Next_Event (Input'Access); 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; |
Modified tests/natools-s_expressions-parsers-tests.ads from [014bfd3a14] to [6b1fcfc480].
︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 | 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; | > | 32 33 34 35 36 37 38 39 40 41 | 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); procedure Subparser_Interface (Report : in out NT.Reporter'Class); end Natools.S_Expressions.Parsers.Tests; |