Debian Codegraph @

deps/ada-toml/tests/api/compare/main.adb

raw
1 with Ada.Text_IO;
2
3 with TOML;
4
5 procedure Main is
6 procedure Assert (Predicate : Boolean; Message : String);
7 -- If Predicate is false, emit the given error Message
8
9 procedure Assert_Eq (Left, Right : TOML.TOML_Value; Message : String);
10 -- Shortcut for Assert (TOML.Equals (Left, Right), Message)
11
12 procedure Assert_Ne (Left, Right : TOML.TOML_Value; Message : String);
13 -- Shortcut for Assert (not TOML.Equals (Left, Right), Message)
14
15 ------------
16 -- Assert --
17 ------------
18
19 procedure Assert (Predicate : Boolean; Message : String) is
20 begin
21 if not Predicate then
22 Ada.Text_IO.Put_Line ("Test failed: " & Message);
23 end if;
24 end Assert;
25
26 ---------------
27 -- Assert_Eq --
28 ---------------
29
30 procedure Assert_Eq (Left, Right : TOML.TOML_Value; Message : String) is
31 begin
32 Assert (TOML.Equals (Left, Right), Message);
33 end Assert_Eq;
34
35 ---------------
36 -- Assert_Ne --
37 ---------------
38
39 procedure Assert_Ne (Left, Right : TOML.TOML_Value; Message : String) is
40 begin
41 Assert (not TOML.Equals (Left, Right), Message);
42 end Assert_Ne;
43
44 use TOML;
45
46 begin
47 Assert_Ne
48 (Create_String ("ABCD"), Create_Integer (0), "different kinds");
49
50 Assert_Eq
51 (Create_Boolean (True), Create_Boolean (True), "same boolean");
52 Assert_Ne
53 (Create_Boolean (True), Create_Boolean (False), "different boolean");
54
55 Assert_Eq
56 (Create_Integer (0), Create_Integer (0), "same integer");
57 Assert_Ne
58 (Create_Integer (0), Create_Integer (1), "different integer");
59
60 Assert_Eq
61 (Create_String ("ABCD"), Create_String ("ABCD"), "same string");
62 Assert_Ne
63 (Create_String ("ABCD"), Create_String ("ABCDE"), "different string");
64
65 declare
66 Empty_1 : constant TOML_Value := Create_Array;
67 Empty_2 : constant TOML_Value := Create_Array;
68
69 One_Int_1 : constant TOML_Value := Create_Array;
70 One_Int_2 : constant TOML_Value := Create_Array;
71 Two_Ints : constant TOML_Value := Create_Array;
72 One_String : constant TOML_Value := Create_Array;
73 begin
74 One_Int_1.Append (Create_Integer (0));
75 One_Int_2.Append (Create_Integer (0));
76 Two_Ints.Append (Create_Integer (0));
77 Two_Ints.Append (Create_Integer (1));
78 One_String.Append (Create_String ("ABCD"));
79
80 Assert_Eq (Empty_1, Empty_2, "empty arrays");
81 Assert_Ne (Empty_1, One_Int_1, "different array length");
82
83 Assert_Eq (One_Int_1, One_Int_2, "same int array");
84 Assert_Ne (One_Int_1, Two_Ints, "different int array");
85 Assert_Ne (One_Int_1, One_String, "different array item kind");
86 end;
87
88 declare
89 Empty_1 : constant TOML_Value := Create_Table;
90 Empty_2 : constant TOML_Value := Create_Table;
91
92 Same_Key_1 : constant TOML_Value := Create_Table;
93 Same_Key_2 : constant TOML_Value := Create_Table;
94 Same_Key_3 : constant TOML_Value := Create_Table;
95
96 Different_Key : constant TOML_Value := Create_Table;
97 begin
98 Same_Key_1.Set ("key", Create_Boolean (True));
99 Same_Key_2.Set ("key", Create_Boolean (True));
100 Same_Key_3.Set ("key", Create_Boolean (False));
101 Different_Key.Set ("KEY", Create_Boolean (True));
102
103 Assert_Eq (Empty_1, Empty_2, "empty tables");
104 Assert_Ne (Empty_1, Same_Key_1, "different table size");
105
106 Assert_Eq (Same_Key_1, Same_Key_2, "same table content");
107 Assert_Ne (Same_Key_1, Same_Key_3, "different member value");
108
109 Assert_Ne (Same_Key_1, Different_Key, "different key");
110 end;
111
112 Ada.Text_IO.Put_Line ("Done");
113 end Main;