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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
// file : tests/package-version/driver.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <string>
#include <cassert>
#include <cstdint> // uint16
#include <iostream>
#include <exception>
#include <stdexcept> // invalid_argument
#include <bpkg/manifest>
using namespace std;
using namespace bpkg;
static bool
bad_version (const string& v)
{
try
{
version bv (v);
return false;
}
catch (const invalid_argument&)
{
return true;
}
}
static bool
bad_version (uint16_t e, const string& u, uint16_t r)
{
try
{
version bv (e, u, r);
return false;
}
catch (const invalid_argument&)
{
return true;
}
}
static bool
test_constructor (const version& v)
{
return v == version (v.epoch, v.upstream, v.revision);
}
int
main (int argc, char* argv[])
{
if (argc != 1)
{
cerr << "usage: " << argv[0] << endl;
return 1;
}
try
{
assert (bad_version ("")); // Empty upstream.
assert (bad_version ("1+")); // Same.
assert (bad_version ("1+-3")); // Same.
assert (bad_version ("-3")); // Same.
assert (bad_version ("+3.5")); // Empty epoch.
assert (bad_version ("a-")); // Empty revision.
assert (bad_version ("1+2+4.1-3")); // Extra epoch.
assert (bad_version ("3.5-1-4")); // Extra revision.
assert (bad_version ("1++2-3")); // Duplicated epoch separator.
assert (bad_version ("1+2--3")); // Duplicated revision separator.
assert (bad_version ("a.394857391.3")); // Too long numeric component.
assert (bad_version ("a.000000000.3")); // Too long numeric zero component.
assert (bad_version ("65536+q.3")); // Too big epoch.
assert (bad_version ("1+q-65536")); // Too big revision.
assert (bad_version ("3.5+1.4")); // Components in epoch.
assert (bad_version ("3.5-1.4")); // Components in revision.
assert (bad_version ("3 5-1")); // Non alpha-numeric in upstream.
assert (bad_version ("1+ -3")); // Same.
assert (bad_version ("3 5+4-1")); // Non alpha-numeric in epoch.
assert (bad_version ("2b+a")); // Same.
assert (bad_version ("1+34.1-3 5")); // Non alpha-numeric in revision.
assert (bad_version ("a-3s")); // Same.
assert (bad_version ("a.")); // Not completed upstream.
assert (bad_version ("a..b")); // Empty upstream component.
assert (bad_version (1, "1+1.1", 2)); // Epoch in upstream.
assert (bad_version (1, "1.1-1", 2)); // Revision in upstream.
{
version v ("a");
assert (v.string () == "a");
assert (v.canonical_upstream == "a");
assert (test_constructor (v));
}
{
version v ("65535+ab-65535");
assert (v.string () == "65535+ab-65535");
assert (v.canonical_upstream == "ab");
assert (test_constructor (v));
}
{
version v ("1");
assert (v.string () == "1");
assert (v.canonical_upstream == "00000001");
assert (test_constructor (v));
}
{
version v ("0");
assert (v.string () == "0");
assert (v.canonical_upstream.empty ());
assert (test_constructor (v));
}
{
version v ("0.0.0");
assert (v.string () == "0.0.0");
assert (v.canonical_upstream.empty ());
assert (test_constructor (v));
}
{
version v ("1.0.0");
assert (v.string () == "1.0.0");
assert (v.canonical_upstream == "00000001");
assert (test_constructor (v));
}
{
version v ("0.1.00");
assert (v.string () == "0.1.00");
assert (v.canonical_upstream == "00000000.00000001");
assert (test_constructor (v));
}
{
version v ("0.0a.00");
assert (v.string () == "0.0a.00");
assert (v.canonical_upstream == "00000000.0a");
assert (test_constructor (v));
}
{
version v ("0.a00.00");
assert (v.string () == "0.a00.00");
assert (v.canonical_upstream == "00000000.a00");
assert (test_constructor (v));
}
{
version v ("1+0");
assert (v.string () == "1+0");
assert (v.canonical_upstream.empty ());
assert (test_constructor (v));
}
{
version v ("0+A-1");
assert (v.string () == "A-1");
assert (v.canonical_upstream == "a");
assert (test_constructor (v));
}
{
version v ("10+B-0");
assert (v.string () == "10+B");
assert (v.canonical_upstream == "b");
assert (test_constructor (v));
}
{
version v ("3+1A.31.0.4.0-7");
assert (v.string () == "3+1A.31.0.4.0-7");
assert (v.canonical_upstream == "1a.00000031.00000000.00000004");
assert (test_constructor (v));
}
assert (version ("a") == version ("a"));
assert (version ("a") < version ("b"));
assert (version ("a") < version ("aa"));
assert (version ("a.a") < version ("aaa"));
assert (version ("a") < version ("a.a"));
assert (version ("ab") == version ("ab"));
assert (version ("ac") < version ("bc"));
assert (version ("ab-0") == version ("ab"));
assert (version ("a.1-1") > version ("a.1"));
assert (version ("0+ab") == version ("ab"));
assert (version ("1.2") > version ("1.1"));
assert (version ("1+1.0") > version ("2.0"));
assert (version ("0+ab-1") == version ("ab-1"));
assert (version ("0+ab-1").compare (version ("0+ab-2"), true) == 0);
assert (version ("12") > version ("2"));
assert (version ("2") < version ("12"));
assert (version ("1") == version ("01"));
assert (version ("1") == version ("1.0"));
assert (version ("1.3") == version ("1.3.0"));
assert (version ("1.3") == version ("1.3.0.0"));
assert (version ("1.3.1") > version ("1.3"));
assert (version ("1.30") > version ("1.5"));
assert (version ("1.alpha.1") < version ("1.Beta.1"));
assert (version ("1.Alpha.1") < version ("1.beta.1"));
assert (version ("1.Alpha.1") == version ("1.ALPHA.1"));
assert (version ("a.1") < version ("ab1"));
assert (version ("a.2") < version ("a.1b"));
assert (version ("0.0.0") == version ("0"));
assert (version ("1.0.0") == version ("01"));
assert (version ("0.1.00") == version ("00.1"));
assert (version ("0.0a.00") == version ("00.0a"));
}
catch (const exception& e)
{
cerr << e.what () << endl;
return 1;
}
}
|