vss_24.0.0_b4d0be7c/testsuite/text/generic_ucd_break_test_runner.adb

  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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
--
--  Copyright (C) 2021, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

with Ada.Characters.Wide_Wide_Latin_1;
with Ada.Wide_Wide_Text_IO;

with VSS.Characters;
with VSS.Unicode;

procedure Generic_UCD_Break_Test_Runner (File_Name : String) is

   procedure Parse_Test_Case
     (Buffer   : Wide_Wide_String;
      String   : out VSS.Strings.Virtual_String;
      Segments : out VSS.String_Vectors.Virtual_String_Vector);

   ---------------------
   -- Parse_Test_Case --
   ---------------------

   procedure Parse_Test_Case
     (Buffer   : Wide_Wide_String;
      String   : out VSS.Strings.Virtual_String;
      Segments : out VSS.String_Vectors.Virtual_String_Vector)
   is
      First   : Positive := Buffer'First;
      Last    : Natural;
      Segment : VSS.Strings.Virtual_String;

   begin
      String.Clear;
      Segments.Clear;

      if Buffer (First) /= '÷' then
         raise Program_Error;
      end if;

      First := First + 1;
      Segment.Clear;

      loop
         exit when First > Buffer'Last;

         --  Skip spaces

         for J in First .. Buffer'Last loop
            First := J;

            exit when Buffer (J) /= ' ';
         end loop;

         --  Parse code point

         for J in First .. Buffer'Last loop
            Last := J - 1;

            exit when Buffer (J) not in '0' .. '9' | 'A' .. 'F';
         end loop;

         String.Append
           (VSS.Characters.Virtual_Character'Val
              (VSS.Unicode.Code_Point'Wide_Wide_Value
                   ("16#" & Buffer (First .. Last) & '#')));
         Segment.Append
           (VSS.Characters.Virtual_Character'Val
              (VSS.Unicode.Code_Point'Wide_Wide_Value
                   ("16#" & Buffer (First .. Last) & '#')));

         First := Last + 1;

         --  Skip spaces

         for J in First .. Buffer'Last loop
            First := J;

            exit when Buffer (J) /= ' ';
         end loop;

         if Buffer (First) = '÷' then
            Segments.Append (Segment);
            Segment.Clear;
            First := First + 1;

         elsif Buffer (First) = '×' then
            First := First + 1;

         else
            raise Program_Error;
         end if;
      end loop;

      if not Segment.Is_Empty then
         raise Program_Error;
      end if;
   end Parse_Test_Case;

   File        : Ada.Wide_Wide_Text_IO.File_Type;
   Buffer      : Wide_Wide_String (1 .. 1024);
   Buffer_Last : Natural;
   Last        : Natural;

begin
   Ada.Wide_Wide_Text_IO.Open
     (File,
      Ada.Wide_Wide_Text_IO.In_File,
      File_Name,
      "wcem=8");

   while not Ada.Wide_Wide_Text_IO.End_Of_File (File) loop
      Ada.Wide_Wide_Text_IO.Get_Line (File, Buffer, Buffer_Last);
      Last := Buffer_Last;

      for J in Buffer'First .. Buffer_Last loop
         Last := J - 1;

         exit when Buffer (J) = '#';
      end loop;

      for J in reverse Buffer'First .. Last loop
         Last := J;

         exit when Buffer (J)
         not in ' ' | Ada.Characters.Wide_Wide_Latin_1.HT;
      end loop;

      if Last >= Buffer'First then
         declare
            String   : VSS.Strings.Virtual_String;
            Segments : VSS.String_Vectors.Virtual_String_Vector;

         begin
            Parse_Test_Case (Buffer (Buffer'First .. Last), String, Segments);
            Do_Test (String, Segments);
         end;
      end if;
   end loop;

   Ada.Wide_Wide_Text_IO.Close (File);
end Generic_UCD_Break_Test_Runner;