File: recognizer_integer_test.adb

package info (click to toggle)
opentoken 4.0b-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,812 kB
  • ctags: 57
  • sloc: ada: 12,643; makefile: 129; java: 37; sh: 6
file content (83 lines) | stat: -rw-r--r-- 2,545 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--  Abstract :
--
--  Test OpenToken.Recognizer.Integer
--
--  Copyright (C) 2002, 2009 Stephen Leake.  All Rights Reserved.
--
--  This program is free software; you can redistribute it and/or
--  modify it under terms of the GNU General Public License as
--  published by the Free Software Foundation; either version 3, or (at
--  your option) any later version. This program is distributed in the
--  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
--  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
--  PURPOSE. See the GNU General Public License for more details. You
--  should have received a copy of the GNU General Public License
--  distributed with this program; see file COPYING. If not, write to
--  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
--  MA 02111-1307, USA.
--

with Ada.Command_Line;
with Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with OpenToken.Recognizer.Integer; use OpenToken.Recognizer.Integer;
procedure Recognizer_Integer_Test
is
   Recognizer : Instance := Get;

   procedure Test
     (Item         : in String;
      Expect_Match : in Boolean;
      Comment      : in String)
   is
      use OpenToken.Recognizer;
      Verdict : Analysis_Verdict;
      I       : Integer := Item'First;
   begin
      Clear (Recognizer);

      loop
         Analyze (Recognizer, Item (I), Verdict);
         if (Expect_Match and Verdict = Failed) or
           ((not Expect_Match) and Verdict = Matches)
         then
            Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
            Put_Line (Comment & "...failed");
            return;
         end if;

         exit when I = Item'Last;
         I := I + 1;
      end loop;

      Put_Line (Comment & "...passed");
   exception
      when E : others =>
         Put_Line (Comment & "...failed due to exception. " &
                     Ada.Exceptions.Exception_Name (E) &
                     ": " & Ada.Exceptions.Exception_Message (E));
   end Test;

begin
   Test
     (Item         => "1234",
      Expect_Match => True,
      Comment      => "simple integer");

   Test
     (Item         => "-- A comment :)",
      Expect_Match => False,
      Comment      => "Ada comment");

   --  Tests for Debian bug 536359
   Test
     (Item         => "-1234",
      Expect_Match => True,
      Comment      => "negative integer");

   Test
     (Item         => "+1234",
      Expect_Match => True,
      Comment      => "explicitly positive integer");

end Recognizer_Integer_Test;