1 module fdb.tuple;
2 
3 import
4     std.math,
5     std.uuid;
6 
7 public import
8     fdb.tuple.future,
9     fdb.tuple.packer,
10     fdb.tuple.part,
11     fdb.tuple.unpacker;
12 
13 unittest
14 {
15     // Combined null
16     assert(pack(null).unpack!(typeof(null)) is null);
17 
18     // Combined byte array tests
19     assert(pack(cast(ubyte[])[ 0xa0, 0x00, 0x0b ]).unpack!(ubyte[])
20         == cast(ubyte[])[ 0xa0, 0x00, 0x0b ]);
21 
22     // Combined string tests
23     assert(pack("Some useful string").unpack!string
24         == "Some useful string");
25 
26     // Combined long tests
27     assert(pack(-0x08_00_00_00_00_00_00_07).unpack!long
28         == -0x08_00_00_00_00_00_00_07);
29     assert(pack(-0x07_00_00_00_00_00_06).unpack!long
30         == -0x07_00_00_00_00_00_06);
31     assert(pack(-0x06_00_00_00_00_05).unpack!long
32         == -0x06_00_00_00_00_05);
33     assert(pack(-0x05_00_00_00_04).unpack!long
34         == -0x05_00_00_00_04);
35     assert(pack(-0x04_00_00_03).unpack!long
36         == -0x04_00_00_03);
37     assert(pack(-0x03_00_02).unpack!long
38         == -0x03_00_02);
39     assert(pack(-0x02_01).unpack!long
40         == -0x02_01);
41     assert(pack(-0x01).unpack!long
42         == -0x01);
43 
44     assert(pack(0x00).unpack!long
45         == 0x00);
46 
47     assert(pack(0x01).unpack!long
48         == 0x01);
49     assert(pack(0x02_01).unpack!long
50         == 0x02_01);
51     assert(pack(0x03_00_02).unpack!long
52         == 0x03_00_02);
53     assert(pack(0x04_00_00_03).unpack!long
54         == 0x04_00_00_03);
55     assert(pack(0x05_00_00_00_04).unpack!long
56         == 0x05_00_00_00_04);
57     assert(pack(0x06_00_00_00_00_05).unpack!long
58         == 0x06_00_00_00_00_05);
59     assert(pack(0x07_00_00_00_00_00_06).unpack!long
60         == 0x07_00_00_00_00_00_06);
61     assert(pack(0x08_00_00_00_00_00_00_07).unpack!long
62         == 0x08_00_00_00_00_00_00_07);
63 
64     // Combined float tests
65     assert(pack(float.nan).unpack!float.isNaN);
66     assert(pack(-float.infinity).unpack!float   == -float.infinity);
67     assert(pack(-float.max).unpack!float        == -float.max);
68     assert(pack(-1.0f).unpack!float             == -1.0f);
69     assert(pack(-float.min_normal).unpack!float == -float.min_normal);
70     assert(pack(0.0f).unpack!float              ==  0.0f);
71     assert(pack(float.min_normal).unpack!float  ==  float.min_normal);
72     assert(pack(1.0f).unpack!float              ==  1.0f);
73     assert(pack(float.max).unpack!float         ==  float.max);
74     assert(pack(float.infinity).unpack!float    ==  float.infinity);
75 
76     // Combined double tests
77     assert(pack(double.nan).unpack!double.isNaN);
78     assert(pack(-double.infinity).unpack!double   == -double.infinity);
79     assert(pack(-double.max).unpack!double        == -double.max);
80     assert(pack(-1.0).unpack!double               == -1.0);
81     assert(pack(-double.min_normal).unpack!double == -double.min_normal);
82     assert(pack(0.0).unpack!double                ==  0.0);
83     assert(pack(double.min_normal).unpack!double  ==  double.min_normal);
84     assert(pack(1.0).unpack!double                ==  1.0);
85     assert(pack(double.max).unpack!double         ==  double.max);
86     assert(pack(double.infinity).unpack!double    ==  double.infinity);
87 
88     // Combined UUID tests
89     assert(pack(sha1UUID("some value")).unpack!UUID
90         == sha1UUID("some value"));
91 
92     // Combined tests
93     assert(
94         pack(
95             null,
96             cast(ubyte[])[ 0xa0, 0x00, 0x0b ],
97             "some string",
98             -1578,
99             "",
100             598759847,
101             -float.min_normal,
102             double.max,
103             sha1UUID("some value")
104         ).unpack == [
105             Part(null),
106             Part(cast(ubyte[])[ 0xa0, 0x00, 0x0b ]),
107             Part("some string"),
108             Part(-1578L),
109             Part(""),
110             Part(598759847L),
111             Part(-float.min_normal),
112             Part(double.max),
113             Part(sha1UUID("some value"))
114         ]);
115 }