Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | s_expressions-parsers-tests: use new helper procedures to test Descriptor interface of Subparser objects |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
0a35973c17d74b150518a05663121799 |
| User & Date: | nat 2014-02-20 21:55:54.220 |
Context
|
2014-02-21
| ||
| 19:39 | s_expressions-test_tools: new test for Descriptor interface of caches check-in: 6608672b76 user: nat tags: trunk | |
|
2014-02-20
| ||
| 21:55 | s_expressions-parsers-tests: use new helper procedures to test Descriptor interface of Subparser objects check-in: 0a35973c17 user: nat tags: trunk | |
|
2014-02-19
| ||
| 20:43 | s_expressions-test_tools: new helper procedures to update and test a Descriptor in a single call check-in: b5759ad827 user: nat tags: trunk | |
Changes
Changes to tests/natools-s_expressions-parsers-tests.adb.
| ︙ | ︙ | |||
412 413 414 415 416 417 418 |
& "(16:overflowing atom)"));
begin
Test (Report);
end Special_Subexpression;
procedure Subparser_Interface (Report : in out NT.Reporter'Class) is
| | | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
& "(16:overflowing atom)"));
begin
Test (Report);
end Special_Subexpression;
procedure Subparser_Interface (Report : in out NT.Reporter'Class) is
Test : NT.Test := Report.Item ("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);
|
| ︙ | ︙ | |||
439 440 441 442 443 444 445 |
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
| < | < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < | < < < < < < < < < | < < | < < | < | | < | < < | < | < | | | | < | | > | | < | < | > | < < | | < | | < | < < | | 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;
|