commit 19a02ca246e683a4f8dd2f2be29dc2213284a154
parent 7f0cb29f6cbc29061f94db03044632cb940faced
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 5 Dec 2015 23:45:56 -0500
support 4-digits wide version components
Diffstat:
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/version.cpp b/src/version.cpp
@@ -24,10 +24,13 @@ Version::Version(const std::string &str)
throw reapack_error("invalid version name");
for(sregex_iterator it = begin; it != end; it++) {
- const smatch match = *it;
+ const string match = it->str(1);
const size_t index = distance(begin, it);
- m_code += stoi(match[1]) * (size_t)pow(1000, size - index - 1);
+ if(match.size() > 4)
+ throw reapack_error("version component overflow");
+
+ m_code += stoi(match) * (size_t)pow(10000, size - index - 1);
}
}
diff --git a/test/version.cpp b/test/version.cpp
@@ -7,7 +7,7 @@
using namespace std;
-static const char *M = "[database]";
+static const char *M = "[version]";
TEST_CASE("invalid", M) {
try {
@@ -22,34 +22,50 @@ TEST_CASE("invalid", M) {
TEST_CASE("major minor patch version", M) {
Version ver("1.2.3");
REQUIRE(ver.name() == "1.2.3");
- REQUIRE(ver.code() == 1002003000);
+ REQUIRE(ver.code() == 1000200030000);
}
TEST_CASE("major minor version", M) {
Version ver("1.2");
REQUIRE(ver.name() == "1.2");
- REQUIRE(ver.code() == 1002000000);
+ REQUIRE(ver.code() == 1000200000000);
}
TEST_CASE("major version", M) {
Version ver("1");
REQUIRE(ver.name() == "1");
- REQUIRE(ver.code() == 1000000000);
+ REQUIRE(ver.code() == 1000000000000);
}
TEST_CASE("version with string suffix", M) {
Version ver("1.2pre3");
REQUIRE(ver.name() == "1.2pre3");
- REQUIRE(ver.code() == 1002003000);
+ REQUIRE(ver.code() == 1000200030000);
}
TEST_CASE("version with 4 components", M) {
Version ver("1.2.3.4");
REQUIRE(ver.name() == "1.2.3.4");
- REQUIRE(ver.code() == 1002003004);
+ REQUIRE(ver.code() == 1000200030004);
REQUIRE(ver < Version("1.2.4"));
}
+TEST_CASE("4 digits version component", M) {
+ Version ver("0.2015.12.25");
+ REQUIRE(ver.name() == "0.2015.12.25");
+ REQUIRE(ver.code() == 201500120025);
+}
+
+TEST_CASE("5 digits version component", M) {
+ try {
+ Version ver("12345.1");
+ FAIL();
+ }
+ catch(const reapack_error &e) {
+ REQUIRE(string(e.what()) == "version component overflow");
+ }
+}
+
TEST_CASE("version with 5 components", M) {
try {
Version ver("1.2.3.4.5");