uxstrings_0.6.0_c9bcce5c/tests/test_uxstrings.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
with UXStrings;   use UXStrings;
with UXStrings.Text_IO; use UXStrings.Text_IO;
with UXStrings.Conversions;
with UXStrings.Hash;
with UXStrings.Formatting;
with UXStrings.Lists;
with Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants;

procedure Test_UXStrings is

   function Image is new UXStrings.Conversions.Scalar_Image (Boolean);
   function Image is new UXStrings.Conversions.Integer_Image (Integer);
   function Value is new UXStrings.Conversions.Integer_Value (Integer);

   function Format is new UXStrings.Formatting.Integer_Format (Natural);
   use all type UXStrings.Formatting.Alignment;

   procedure Send (Msg : UTF_8_Character_Array) is
   begin
      for Code of Msg loop
         Put (Image(Character'pos (Code), 16));
      end loop;
      New_Line;
   end;
   function Receive return UTF_8_Character_Array is (To_UTF_8("données"));

   S1, S2, S3 : UXString;
   C          : Character;
   WC         : Wide_Character;
   WWC        : Wide_Wide_Character;
   F          : Boolean;
   D : constant array (Positive range <>) of Natural := (16#0075#, 16#003E#, 16#30E3#, 16#03A3#);
   --     Data : constant BMP_Character_array := (for I in D'Range => BMP_Character'val (D(I)));

   UXSL1 : constant UXStrings.Lists.UXString_List := ["Ada", "Strings", "Wide_Wide_Maps", "Wide_Wide_Constants", "Lower_Case_Map"];
   S4 : constant UXString := "Ada.Strings.Wide_Wide_Maps.Is_Subset(Item, My_Set)";
   S5 : constant UXString := "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/Current/lib/libpython3.9.dylib";

begin
   -- Change the default to LF and UTF-8
   Ending (Current_Output, LF_Ending);
   Line_Mark (LF_Ending);
   Scheme (Current_Output, UTF_8);

   S1 := From_Latin_1 ("était blah blah");
   S2 := From_BMP ("une soirée passée à étudier la physique ω=Δθ/Δt...");
   S3 := From_Unicode ("une soirée passée à étudier les mathématiques ℕ⊂𝕂...");
   Put_Line (S1 & Line_Mark & S2 & Line_Mark & S3);
   Send (To_UTF_8 (S1) & To_UTF_8 (S3));
   S2  := "Received: " & From_UTF_8 (Receive);
   S3 := S1 & " - Sent ok";
   Put_Line (S1 & Line_Mark & S2 & Line_Mark & S3);
   S1 := 4*'.';
   --     S2 := From_BMP (Data);
   --     S3 := 4*'.';
   --     for I in Data'Range loop
   --        S3(I) := Data (I); -- discriminant check failed
   --     end loop;
   Put_Line (S1 & Line_Mark & S2 & Line_Mark & S3);
   S1 := "était blah blah";
   S2 := "une soirée passée à étudier la physique ω=Δθ/Δt...";
   S3 := "une soirée passée à étudier les mathématiques ℕ⊂𝕂...";
   Put_Line (S1 & Line_Mark & S2 & Line_Mark & S3);
   Put_Line (Image(Index (S1, "ée")) & Image(Index (S2, "ée"),prefix=> ' ') & Image(index (S3, "ée", 10),prefix =>' '));
   C   := S1.Get_Latin_1 (6);
   WC  := S1.Get_BMP (7);
   WWC := S1 (1);
   Put_Line (Image(Character'pos (C), 16) & ',' & Image(Wide_Character'pos (WC), 16)  & ','& Image(Wide_Wide_Character'pos (WWC), 16));
   for I in S3 loop
      F   := S3.Get_Latin_1 (I) = 'é';
--        if F then
--           Replace_Latin_1 (S2 ,I, 'e');
--        end if;
      WWC := S3 (I);
      Put_Line (Image(I) & ':' & Image(Wide_Wide_Character'pos (WWC), 16) & ',' & Image(F));
   end loop;
   for CC of S2 loop
      WWC := CC;
      F   := CC = 'é';
      Put_Line (Image(Wide_Wide_Character'pos (WWC), 16)  & ','& Image(F));
   end loop;
--     Replace_Unicode (S1 ,3, WWC);
--     S1.Replace_BMP (2, WC);
--     S1.Replace_Latin_1 (1, C);
--     Put_Line (S1);
   if S1 /= "test" then
      S1 := Null_UXString;
      S2 := 2 * 'z';
      S3 := 4 * "po";
   end if;
   S3 := "Riri";
   S2 := "Loulou";
   S1 := " et Fifi";
   S2.Append (S1);
   S1.Prepend(S3);
   Put_Line (S1 & Line_Mark & S2 & Line_Mark & S3);
   Put_Line (Image(Integer(UXStrings.Hash(S1)),16));
   Put_Line (Image (Value("  + 73")));
   C := S1.To_Latin_1 (3);
   Put_Line (Image(Character'pos (C), 16));
   C := S1.Get_Latin_1 (3); -- same result but avoid all string conversion
   Put_Line (Image(Character'pos (C), 16));
   Put_Line (Format (5, 2, True, 10, Center, '@'));

   Put_Line (Image(S1.Contains ("Riri")));
   Put_Line (Image(S1.Contains ("et", Insensitive)));
   Put_Line (Image(S2.Contains ("Riri")));
   Put_Line (Image(S2.Count ("lo", Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants.Lower_Case_Map)));
   Put_Line (Image(S2.Ends_With ("Fifi")));
   Put_Line (Image(S3.Ends_With ("Loulou")));
   Put_Line (Image(S3.Starts_With ("riri", Insensitive)));
   Put_Line (Image(S2.Is_Lower ));
   Put_Line (Image(S2.Is_Upper) );
   Put_Line (Image(S2.Is_Basic ));
   Put_Line (Image(S2.Is_Empty ));
   Put_Line (S2.Remove ("ou"));
   Put_Line (S2.Remove ("fi", Insensitive) & '.');
   Put_Line (S2.Replace ("lou", "Coin", Insensitive));

   for E of UXSL1 loop
      Put_Line (E);
   end loop;
   for E of S4.Split(Ada.Strings.Wide_Wide_Maps.To_Set(".(,) ")).Sort loop
      Put_Line (E);
   end loop;
   Put_Line (UXSL1.Join ('-').To_Lower);
   for E of S5.Split('/').Filter ("py", Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants.Lower_Case_Map) loop
      Put_Line (E);
   end loop;

   Put_Line ("--end--");
end Test_UXStrings;