reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 5f1b28e8506226d6f2803e26bc6e915a88f8f1a7
parent 67ed5f2d3efcd0b9dab3d427d1faa2da7fd9f44e
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 28 Nov 2015 16:44:56 -0500

limit version strings to 4 numeric components

Diffstat:
Msrc/version.cpp | 10+++++-----
Msrc/version.hpp | 4++--
Mtest/version.cpp | 21++++++++++++++++-----
3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/version.cpp b/src/version.cpp @@ -16,12 +16,12 @@ Version::Version(const std::string &str) auto begin = sregex_iterator(str.begin(), str.end(), pattern); auto end = sregex_iterator(); - if(begin == end) - throw reapack_error("invalid version name"); - // set the major version by default - // even if there are less than 3 numeric components in the string - const int size = std::max(3L, distance(begin, end)); + // even if there are less than 4 numeric components in the string + const int size = std::max(4L, distance(begin, end)); + + if(begin == end || size > 4L) + throw reapack_error("invalid version name"); for(sregex_iterator it = begin; it != end; it++) { const smatch match = *it; diff --git a/src/version.hpp b/src/version.hpp @@ -16,7 +16,7 @@ public: Version(const std::string &); const std::string &name() const { return m_name; } - int code() const { return m_code; } + unsigned long code() const { return m_code; } void setChangelog(const std::string &); const std::string &changelog() const { return m_changelog; } @@ -29,7 +29,7 @@ public: private: std::string m_name; - int m_code; + unsigned long m_code; std::string m_changelog; std::vector<SourcePtr> m_sources; diff --git a/test/version.cpp b/test/version.cpp @@ -22,31 +22,42 @@ 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() == 1002003); + REQUIRE(ver.code() == 1002003000); } TEST_CASE("major minor version", M) { Version ver("1.2"); REQUIRE(ver.name() == "1.2"); - REQUIRE(ver.code() == 1002000); + REQUIRE(ver.code() == 1002000000); } TEST_CASE("major version", M) { Version ver("1"); REQUIRE(ver.name() == "1"); - REQUIRE(ver.code() == 1000000); + REQUIRE(ver.code() == 1000000000); } TEST_CASE("version with string suffix", M) { Version ver("1.2pre3"); REQUIRE(ver.name() == "1.2pre3"); - REQUIRE(ver.code() == 1002003); + REQUIRE(ver.code() == 1002003000); } -TEST_CASE("version with extra integer", M) { +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 < Version("1.2.4")); +} + +TEST_CASE("version with 5 components", M) { + try { + Version ver("1.2.3.4.5"); + FAIL(); + } + catch(const reapack_error &e) { + REQUIRE(string(e.what()) == "invalid version name"); + } } TEST_CASE("convert platforms", M) {