iso_2.0.0_abd8a59c/tests/src/iso_countries_tests.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
with Ada.Assertions; use Ada.Assertions;
with ISO.Countries; use ISO.Countries;
with Ada.Locales;
package body ISO_Countries_Tests is
   procedure Run_Tests is

      --  Create some countries.
      US_1 : constant Country := From_Alpha2 ("US");
      US_2 : constant Country := From_Alpha3 ("USA");

      --  Create some countries based on numeric.
      Bosnia_1 : constant Country := From_Numeric (070);
      Bosnia_2 : constant Country := From_Numeric ("070");

      --  Create a country based on ada-spec country code
      AU_Code_1 : constant Ada.Locales.Country_Code := "AU";
      AU        : constant Country := ISO.Countries.From_Country_Code (AU_Code_1);
      AU_Code_2 : constant Ada.Locales.Country_Code := AU.Country_Code;

      --  For Testing all countries
      A : constant All_Countries := Init_Countries;

      --  For testing undefined` country
      Undef : Country;

   begin

      --  Validate default initialization
      Assert (Undef.Name = "Undefined", "Undef failed.");
      Assert (Undef.Alpha2 = "ZZ", "Undef failed.");
      Assert (Undef.Alpha3 = "ZZZ", "Undef failed.");
      Assert (Undef.Numeric = 0, "Undef failed.");

      --  Validate USA
      Assert (US_1 = US_2, "Country Failed");
      Assert (US_1.Name = "United States of America (the)", "US Name failed.");
      Assert (US_1.Alpha2 = "US", "US Alpha2 failed");
      Assert (US_1.Alpha3 = "USA", "US Alpha3 failed");
      Assert (US_1.Numeric = 840, "US Numeric failed");

      --  Validate Bosnia
      Assert (Bosnia_1 = Bosnia_2, "Country Failed");
      Assert (Bosnia_1.Name = "Bosnia and Herzegovina", "Bosnia name failed");
      Assert (Bosnia_1.Alpha2 = "BA", "Bosnia Alpha2 failed");
      Assert (Bosnia_1.Alpha3 = "BIH", "Bosnia Alpha3 failed");
      Assert (Bosnia_1.Numeric = 070, "Bosnia Numeric failed");

      --  Validate Country Codes
      declare
         use Ada.Locales;
      begin
         Assert (AU_Code_1 = AU_Code_2, "Country Code failed");
         Assert (Undef.Country_Code = "ZZ", "Undef failed.");
      end;

      --  Validate array.
      Assert (A (C_US).Name = "United States of America (the)", "Index Validation Failed.");
      for X of A loop
         Assert (X.Name = From_Alpha2  (X.Alpha2).Name, "All Countries Failed.");
         Assert (X.Name = From_Alpha3  (X.Alpha3).Name, "All Countries Failed.");
         Assert (X.Name = From_Numeric (X.Numeric).Name, "All Countries Failed.");
         Assert (X.Name = From_Numeric (X.Numeric'Image).Name, "All Countries Failed.");
      end loop;

      --  Check if all country codes are valid alpha2s.
      for C in Country_Key'Range loop
         declare
            Test_String : constant String := C'Image;
            Test_Code : constant Alpha2_Code := Test_String (Test_String'Last - 1 .. Test_String'Last);
         begin
            null;
         end;
      end loop;

      --  All tests have passed.
   end Run_Tests;
end ISO_Countries_Tests;