reapack

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

commit 994021d50e24f16d9cb479cbc5ea2e62bf9c7bff
parent 7a618ddc95ac73f91010d26254bb8275b2a25415
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 15 Dec 2016 01:42:55 -0500

version: refactoring – split into Version and VersionName classes

Diffstat:
Msrc/about.cpp | 15++++++++-------
Msrc/about.hpp | 4++--
Msrc/browser.cpp | 29+++++++++++++++--------------
Msrc/ostream.cpp | 2+-
Msrc/package.cpp | 10+++++-----
Msrc/package.hpp | 6+++---
Msrc/registry.cpp | 8++++----
Msrc/registry.hpp | 3++-
Msrc/report.cpp | 4++--
Msrc/task.cpp | 2+-
Msrc/transaction.cpp | 4++--
Msrc/version.cpp | 101++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/version.hpp | 62++++++++++++++++++++++++++++++++++++--------------------------
Mtest/helper/io.cpp | 2+-
Mtest/index_v1.cpp | 2+-
Mtest/package.cpp | 12++++++------
Mtest/registry.cpp | 20++++++++++----------
Mtest/version.cpp | 141+++++++++++++++++++++++++++++++++++++------------------------------------------
18 files changed, 216 insertions(+), 211 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -296,7 +296,7 @@ void AboutIndexDelegate::init(About *dialog) dialog->list()->setSortCallback(1, [&] (const int a, const int b) { const Version *l = m_packagesData->at(a)->lastVersion(); const Version *r = m_packagesData->at(b)->lastVersion(); - return l->compare(*r); + return l->name().compare(r->name()); }); initInstalledFiles(); @@ -362,7 +362,7 @@ void AboutIndexDelegate::updateList(const int index) for(const Package *pkg : *m_packagesData) { const Version *lastVer = pkg->lastVersion(); const auto_string &name = make_autostring(pkg->displayName()); - const auto_string &version = make_autostring(lastVer->name()); + const auto_string &version = make_autostring(lastVer->name().toString()); const auto_string &author = make_autostring(lastVer->displayAuthor()); m_dialog->list()->addRow({name, version, author}); @@ -423,7 +423,7 @@ void AboutIndexDelegate::aboutPackage() { const Package *pkg = currentPackage(); - Version current; + VersionName current; try { Registry reg(Path::prefixRoot(Path::REGISTRY)); @@ -475,7 +475,7 @@ void AboutIndexDelegate::install() } AboutPackageDelegate::AboutPackageDelegate(const Package *pkg, - const Version &ver, ReaPack *reapack) + const VersionName &ver, ReaPack *reapack) : m_package(pkg), m_current(ver), m_reapack(reapack), m_index(pkg->category()->index()->shared_from_this()) { @@ -500,14 +500,15 @@ void AboutPackageDelegate::init(About *dialog) dialog->list()->addColumn({AUTO_STR("Action List"), 84}); for(const Version *ver : m_package->versions()) { - const auto index = dialog->menu()->addRow({make_autostring(ver->name())}); + const auto index = dialog->menu()->addRow({ + make_autostring(ver->name().toString())}); - if(m_current == *ver) + if(m_current == ver->name()) dialog->menu()->select(index); } dialog->menu()->setSortCallback(0, [&] (const int a, const int b) { - return m_package->version(a)->compare(*m_package->version(b)); + return m_package->version(a)->name().compare(m_package->version(b)->name()); }); dialog->menu()->sortByColumn(0, ListView::DescendingOrder); diff --git a/src/about.hpp b/src/about.hpp @@ -122,7 +122,7 @@ private: class AboutPackageDelegate : public AboutDelegate { public: - AboutPackageDelegate(const Package *, const Version &current, ReaPack *); + AboutPackageDelegate(const Package *, const VersionName &current, ReaPack *); protected: void init(About *) override; @@ -141,7 +141,7 @@ private: void locate(); const Package *m_package; - Version m_current; + VersionName m_current; ReaPack *m_reapack; IndexPtr m_index; // keeps the package loaded in memory const std::vector<const Source *> *m_sources; diff --git a/src/browser.cpp b/src/browser.cpp @@ -102,18 +102,18 @@ void Browser::onInit() const Entry &a = m_entries[m_visibleEntries[ai]]; const Entry &b = m_entries[m_visibleEntries[bi]]; - const Version *l = nullptr; - const Version *r = nullptr; + const VersionName *l = nullptr; + const VersionName *r = nullptr; if(a.test(InstalledFlag)) l = &a.regEntry.version; else - l = a.latest; + l = &a.latest->name(); if(b.test(InstalledFlag)) r = &b.regEntry.version; else - r = b.latest; + r = &b.latest->name(); return l->compare(*r); }); @@ -331,7 +331,7 @@ void Browser::fillMenu(Menu &menu) auto_char installLabel[32] = {}; auto_snprintf(installLabel, auto_size(installLabel), AUTO_STR("U&pdate to v%s"), - make_autostring(entry->latest->name()).c_str()); + make_autostring(entry->latest->name().toString()).c_str()); const UINT actionIndex = menu.addAction(installLabel, ACTION_LATEST); if(entry->target && *entry->target == entry->latest) @@ -341,7 +341,7 @@ void Browser::fillMenu(Menu &menu) auto_char reinstallLabel[32] = {}; auto_snprintf(reinstallLabel, auto_size(reinstallLabel), AUTO_STR("&Reinstall v%s"), - make_autostring(entry->regEntry.version.name()).c_str()); + make_autostring(entry->regEntry.version.toString()).c_str()); const UINT actionIndex = menu.addAction(reinstallLabel, ACTION_REINSTALL); if(!entry->current || entry->test(ObsoleteFlag)) @@ -353,7 +353,7 @@ void Browser::fillMenu(Menu &menu) auto_char installLabel[32] = {}; auto_snprintf(installLabel, auto_size(installLabel), AUTO_STR("&Install v%s"), - make_autostring(entry->latest->name()).c_str()); + make_autostring(entry->latest->name().toString()).c_str()); const UINT actionIndex = menu.addAction(installLabel, ACTION_LATEST); if(entry->target && *entry->target == entry->latest) @@ -369,7 +369,8 @@ void Browser::fillMenu(Menu &menu) int verIndex = (int)versions.size(); for(const Version *ver : versions | boost::adaptors::reversed) { const UINT actionIndex = versionMenu.addAction( - make_autostring(ver->name()).c_str(), --verIndex | (ACTION_VERSION << 8)); + make_autostring(ver->name().toString()).c_str(), + --verIndex | (ACTION_VERSION << 8)); if(entry->target ? *entry->target == ver : ver == entry->current) { if(entry->target && ver != entry->latest) @@ -629,7 +630,7 @@ void Browser::transferActions() if(target) { const Package *pkg = entryIt->package; - if(!pkg || !(target = pkg->findVersion(*target))) + if(!pkg || !(target = pkg->findVersion(target->name()))) continue; } @@ -659,7 +660,7 @@ auto Browser::makeEntry(const Package *pkg, if(regEntry) { flags |= InstalledFlag; - if(latest && regEntry.version < *latest) + if(latest && regEntry.version < latest->name()) flags |= OutOfDateFlag; current = pkg->findVersion(regEntry.version); @@ -770,18 +771,18 @@ string Browser::getValue(const Column col, const Entry &entry) const return pkg ? pkg->category()->name() : regEntry.category; case VersionColumn: if(entry.test(InstalledFlag)) - display = regEntry.version.name(); + display = regEntry.version.toString(); - if(ver && (!regEntry || *ver > regEntry.version)) { + if(ver && (!regEntry || ver->name() > regEntry.version)) { if(!display.empty()) display += '\x20'; - display += '(' + ver->name() + ')'; + display += '(' + ver->name().toString() + ')'; } return display; case AuthorColumn: - return ver ? ver->displayAuthor() : regEntry.version.displayAuthor(); + return ver ? ver->displayAuthor() : Version::displayAuthor(regEntry.author); case TypeColumn: return pkg ? pkg->displayType() : Package::displayType(regEntry.type); case RemoteColumn: diff --git a/src/ostream.cpp b/src/ostream.cpp @@ -46,7 +46,7 @@ void OutputStream::indented(const string &text) OutputStream &OutputStream::operator<<(const Version &ver) { - m_stream << 'v' << ver.name(); + m_stream << 'v' << ver.name().toString(); if(!ver.author().empty()) m_stream << " by " << ver.author(); diff --git a/src/package.cpp b/src/package.cpp @@ -117,25 +117,25 @@ const Version *Package::version(const size_t index) const return *it; } -const Version *Package::lastVersion(const bool pres, const Version &from) const +const Version *Package::lastVersion(const bool pres, const VersionName &from) const { if(m_versions.empty()) return nullptr; for(const Version *ver : m_versions | boost::adaptors::reversed) { - if(*ver < from) + if(ver->name() < from) break; - else if(ver->isStable() || pres) + else if(ver->name().isStable() || pres) return ver; } return from.isStable() ? nullptr : *m_versions.rbegin(); } -const Version *Package::findVersion(const Version &ver) const +const Version *Package::findVersion(const VersionName &ver) const { const auto &it = find_if(m_versions.begin(), m_versions.end(), - [=] (const Version *cur) { return *cur == ver; }); + [=] (const Version *cur) { return cur->name() == ver; }); if(it == m_versions.end()) return nullptr; diff --git a/src/package.hpp b/src/package.hpp @@ -60,15 +60,15 @@ public: bool addVersion(const Version *ver); const auto &versions() const { return m_versions; } const Version *version(size_t index) const; - const Version *lastVersion(bool pres = true, const Version &from = {}) const; - const Version *findVersion(const Version &) const; + const Version *lastVersion(bool pres = true, const VersionName &from = {}) const; + const Version *findVersion(const VersionName &) const; private: class CompareVersion { public: bool operator()(const Version *l, const Version *r) const { - return *l < *r; + return l->name() < r->name(); } }; diff --git a/src/registry.cpp b/src/registry.cpp @@ -156,7 +156,7 @@ auto Registry::push(const Version *ver, vector<Path> *conflicts) -> Entry if(entryId) { m_updateEntry->bind(1, pkg->description()); m_updateEntry->bind(2, pkg->type()); - m_updateEntry->bind(3, ver->name()); + m_updateEntry->bind(3, ver->name().toString()); m_updateEntry->bind(4, ver->author()); m_updateEntry->bind(5, entryId); m_updateEntry->exec(); @@ -167,7 +167,7 @@ auto Registry::push(const Version *ver, vector<Path> *conflicts) -> Entry m_insertEntry->bind(3, pkg->name()); m_insertEntry->bind(4, pkg->description()); m_insertEntry->bind(5, pkg->type()); - m_insertEntry->bind(6, ver->name()); + m_insertEntry->bind(6, ver->name().toString()); m_insertEntry->bind(7, ver->author()); m_insertEntry->exec(); @@ -205,7 +205,7 @@ auto Registry::push(const Version *ver, vector<Path> *conflicts) -> Entry else { release(); return {entryId, ri->name(), cat->name(), - pkg->name(), pkg->description(), pkg->type(), *ver}; + pkg->name(), pkg->description(), pkg->type(), ver->name(), ver->author()}; } } @@ -356,6 +356,6 @@ void Registry::fillEntry(const Statement *stmt, Entry *entry) const entry->description = stmt->stringColumn(col++); entry->type = static_cast<Package::Type>(stmt->intColumn(col++)); entry->version.tryParse(stmt->stringColumn(col++)); - entry->version.setAuthor(stmt->stringColumn(col++)); + entry->author = stmt->stringColumn(col++); entry->pinned = stmt->boolColumn(col++); } diff --git a/src/registry.hpp b/src/registry.hpp @@ -35,7 +35,8 @@ public: std::string package; std::string description; Package::Type type; - Version version; + VersionName version; + std::string author; bool pinned; operator bool() const { return id != 0; } diff --git a/src/report.cpp b/src/report.cpp @@ -119,9 +119,9 @@ void Report::printUpdates() m_stream << pkg->fullName() << ":\r\n"; for(const Version *ver : versions | boost::adaptors::reversed) { - if(*ver <= ticket.previous.version) + if(ver->name() <= ticket.previous.version) break; - else if(*ver <= *ticket.version) + else if(ver->name() <= ticket.version->name()) m_stream << *ver; } } diff --git a/src/task.cpp b/src/task.cpp @@ -126,7 +126,7 @@ void InstallTask::commit() InstallTicket::Type type; - if(m_oldEntry && m_oldEntry.version < *m_version) + if(m_oldEntry && m_oldEntry.version < m_version->name()) type = InstallTicket::Upgrade; else type = InstallTicket::Install; diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -98,11 +98,11 @@ void Transaction::synchronize(const Package *pkg, const InstallOpts &opts) if(!latest) return; - if(regEntry.version == *latest) { + if(regEntry.version == latest->name()) { if(allFilesExists(latest->files())) return; // latest version is really installed, nothing to do here! } - else if(regEntry.pinned || *latest < regEntry.version) + else if(regEntry.pinned || latest->name() < regEntry.version) return; m_currentQueue.push(make_shared<InstallTask>(latest, false, regEntry, this)); diff --git a/src/version.cpp b/src/version.cpp @@ -28,20 +28,16 @@ using boost::format; using namespace std; -Version::Version() - : m_stable(true), m_time(), m_package(nullptr) +string Version::displayAuthor(const string &author) { + if(author.empty()) + return "Unknown"; + else + return author; } Version::Version(const string &str, const Package *pkg) - : m_time(), m_package(pkg) -{ - parse(str); -} - -Version::Version(const Version &o) - : m_name(o.m_name), m_segments(o.m_segments), m_stable(o.m_stable), - m_author(o.m_author), m_package(nullptr) + : m_name(str), m_time(), m_package(pkg) { } @@ -51,7 +47,47 @@ Version::~Version() delete source; } -void Version::parse(const string &str) +string Version::fullName() const +{ + string name = m_package->fullName(); + name += " v"; + name += m_name.toString(); + + return name; +} + +bool Version::addSource(const Source *source) +{ + if(source->version() != this) + throw reapack_error("source belongs to another version"); + else if(!source->platform().test()) + return false; + + const Path path = source->targetPath(); + + if(m_files.count(path)) + return false; + + m_files.insert(path); + m_sources.push_back(source); + + return true; +} + +VersionName::VersionName() : m_stable(true) +{} + +VersionName::VersionName(const string &str) +{ + parse(str); +} + +VersionName::VersionName(const VersionName &o) + : m_string(o.m_string), m_segments(o.m_segments), m_stable(o.m_stable) +{ +} + +void VersionName::parse(const string &str) { static const regex pattern("\\d+|[a-zA-Z]+"); @@ -85,12 +121,12 @@ void Version::parse(const string &str) if(segments.empty()) // version doesn't have any numbers throw reapack_error(format("invalid version name '%s'") % str); - m_name = str; + m_string = str; swap(m_segments, segments); m_stable = letters < 1; } -bool Version::tryParse(const string &str) +bool VersionName::tryParse(const string &str) { try { parse(str); @@ -101,42 +137,7 @@ bool Version::tryParse(const string &str) } } -string Version::fullName() const -{ - string name = m_package->fullName(); - name += " v"; - name += m_name; - - return name; -} - -string Version::displayAuthor() const -{ - if(m_author.empty()) - return "Unknown"; - else - return m_author; -} - -bool Version::addSource(const Source *source) -{ - if(source->version() != this) - throw reapack_error("source belongs to another version"); - else if(!source->platform().test()) - return false; - - const Path path = source->targetPath(); - - if(m_files.count(path)) - return false; - - m_files.insert(path); - m_sources.push_back(source); - - return true; -} - -auto Version::segment(const size_t index) const -> Segment +auto VersionName::segment(const size_t index) const -> Segment { if(index < size()) return m_segments[index]; @@ -144,7 +145,7 @@ auto Version::segment(const size_t index) const -> Segment return 0; } -int Version::compare(const Version &o) const +int VersionName::compare(const VersionName &o) const { const size_t biggest = max(size(), o.size()); diff --git a/src/version.hpp b/src/version.hpp @@ -28,29 +28,55 @@ #include "time.hpp" class Package; -class Source; class Path; +class Source; -class Version { +class VersionName { public: - Version(); - Version(const std::string &, const Package * = nullptr); - Version(const Version &); - ~Version(); + VersionName(); + VersionName(const std::string &); + VersionName(const VersionName &); void parse(const std::string &); bool tryParse(const std::string &); - const std::string &name() const { return m_name; } - std::string fullName() const; size_t size() const { return m_segments.size(); } bool isStable() const { return m_stable; } + const std::string &toString() const { return m_string; } + + int compare(const VersionName &) const; + bool operator<(const VersionName &o) const { return compare(o) < 0; } + bool operator<=(const VersionName &o) const { return compare(o) <= 0; } + bool operator>(const VersionName &o) const { return compare(o) > 0; } + bool operator>=(const VersionName &o) const { return compare(o) >= 0; } + bool operator==(const VersionName &o) const { return compare(o) == 0; } + bool operator!=(const VersionName &o) const { return compare(o) != 0; } + +private: + typedef uint16_t Numeric; + typedef boost::variant<Numeric, std::string> Segment; + + Segment segment(size_t i) const; + + std::string m_string; + std::vector<Segment> m_segments; + bool m_stable; +}; +class Version { +public: + static std::string displayAuthor(const std::string &name); + + Version(const std::string &, const Package * = nullptr); + ~Version(); + + const VersionName &name() const { return m_name; } const Package *package() const { return m_package; } + std::string fullName() const; void setAuthor(const std::string &author) { m_author = author; } const std::string &author() const { return m_author; } - std::string displayAuthor() const; + std::string displayAuthor() const { return displayAuthor(m_author); } void setTime(const Time &time) { if(time) m_time = time; } const Time &time() const { return m_time; } @@ -64,24 +90,8 @@ public: const std::set<Path> &files() const { return m_files; } - int compare(const Version &) const; - bool operator<(const Version &o) const { return compare(o) < 0; } - bool operator<=(const Version &o) const { return compare(o) <= 0; } - bool operator>(const Version &o) const { return compare(o) > 0; } - bool operator>=(const Version &o) const { return compare(o) >= 0; } - bool operator==(const Version &o) const { return compare(o) == 0; } - bool operator!=(const Version &o) const { return compare(o) != 0; } - private: - typedef uint16_t Numeric; - typedef boost::variant<Numeric, std::string> Segment; - - Segment segment(size_t i) const; - - std::string m_name; - std::vector<Segment> m_segments; - bool m_stable; - + VersionName m_name; std::string m_author; std::string m_changelog; Time m_time; diff --git a/test/helper/io.cpp b/test/helper/io.cpp @@ -31,6 +31,6 @@ ostream &operator<<(ostream &os, const Time &time) ostream &operator<<(ostream &os, const Version &ver) { - os << ver.name(); + os << ver.name().toString(); return os; } diff --git a/test/index_v1.cpp b/test/index_v1.cpp @@ -167,7 +167,7 @@ TEST_CASE("full index", M) { REQUIRE(pack->versions().size() == 1); const Version *ver = pack->version(0); - REQUIRE(ver->name() == "1.0"); + REQUIRE(ver->name() == VersionName("1.0")); REQUIRE(ver->changelog() == "Fixed a division by zero error."); REQUIRE(ver->sources().size() == 2); diff --git a/test/package.cpp b/test/package.cpp @@ -160,7 +160,7 @@ TEST_CASE("pre-release updates", M) { pack.addVersion(alpha2); SECTION("pre-release to next pre-release") - REQUIRE(*pack.lastVersion(false, {"1.0-alpha1"}) == *alpha2); + REQUIRE(pack.lastVersion(false, {"1.0-alpha1"}) == alpha2); SECTION("pre-release to latest stable") { Version *stable2 = new Version("1.0", &pack); @@ -175,7 +175,7 @@ TEST_CASE("pre-release updates", M) { beta->addSource(new Source({}, "google.com", beta)); pack.addVersion(beta); - REQUIRE(*pack.lastVersion(false, {"1.0-alpha1"}) == *stable3); + REQUIRE(pack.lastVersion(false, {"1.0-alpha1"}) == stable3); } } @@ -231,13 +231,13 @@ TEST_CASE("find matching version", M) { Version *ver = new Version("1", &pack); ver->addSource(new Source({}, "google.com", ver)); - REQUIRE(pack.findVersion(Version("1")) == nullptr); - REQUIRE(pack.findVersion(Version("2")) == nullptr); + REQUIRE(pack.findVersion({"1"}) == nullptr); + REQUIRE(pack.findVersion({"2"}) == nullptr); pack.addVersion(ver); - REQUIRE(pack.findVersion(Version("1")) == ver); - REQUIRE(pack.findVersion(Version("2")) == nullptr); + REQUIRE(pack.findVersion({"1"}) == ver); + REQUIRE(pack.findVersion({"2"}) == nullptr); } TEST_CASE("package full name", M) { diff --git a/test/registry.cpp b/test/registry.cpp @@ -31,7 +31,7 @@ TEST_CASE("query uninstalled package", M) { const Registry::Entry &entry = reg.getEntry(&pkg); REQUIRE_FALSE(entry); REQUIRE(entry.id == 0); - REQUIRE(entry.version == Version()); + REQUIRE(entry.version == VersionName()); } TEST_CASE("query installed package", M) { @@ -46,8 +46,8 @@ TEST_CASE("query installed package", M) { REQUIRE(entry.category == "Category Name"); REQUIRE(entry.package == "Hello"); REQUIRE(entry.type == Package::ScriptType); - REQUIRE(entry.version.name() == "1.0"); - REQUIRE(entry.version.author() == "John Doe"); + REQUIRE(entry.version.toString() == "1.0"); + REQUIRE(entry.author == "John Doe"); const Registry::Entry &selectEntry = reg.getEntry(&pkg); REQUIRE(selectEntry.id == entry.id); @@ -57,7 +57,7 @@ TEST_CASE("query installed package", M) { REQUIRE(selectEntry.description == entry.description); REQUIRE(selectEntry.type == entry.type); REQUIRE(selectEntry.version == entry.version); - REQUIRE(selectEntry.version.author() == entry.version.author()); + REQUIRE(selectEntry.author == entry.author); } TEST_CASE("bump version", M) { @@ -70,13 +70,13 @@ TEST_CASE("bump version", M) { reg.push(&ver); const Registry::Entry &entry1 = reg.getEntry(&pkg); - REQUIRE(entry1.version.name() == "1.0"); - CHECK(entry1.version.author() == "John Doe"); + REQUIRE(entry1.version.toString() == "1.0"); + CHECK(entry1.author == "John Doe"); reg.push(&ver2); const Registry::Entry &entry2 = reg.getEntry(&pkg); - REQUIRE(entry2.version.name() == "2.0"); - CHECK(entry2.version.author() == ""); + REQUIRE(entry2.version.toString() == "2.0"); + CHECK(entry2.author == ""); REQUIRE(entry2.id == entry1.id); } @@ -113,8 +113,8 @@ TEST_CASE("query all packages", M) { REQUIRE(entries[0].category == "Category Name"); REQUIRE(entries[0].package == "Hello"); REQUIRE(entries[0].type == Package::ScriptType); - REQUIRE(entries[0].version.name() == "1.0"); - REQUIRE(entries[0].version.author() == "John Doe"); + REQUIRE(entries[0].version.toString() == "1.0"); + REQUIRE(entries[0].author == "John Doe"); } TEST_CASE("forget registry entry", M) { diff --git a/test/version.cpp b/test/version.cpp @@ -19,27 +19,25 @@ using namespace std; static const char *M = "[version]"; TEST_CASE("construct null version", M) { - const Version ver; + const VersionName ver; REQUIRE(ver.size() == 0); REQUIRE(ver.isStable()); - REQUIRE_FALSE(ver.time().isValid()); - REQUIRE(ver.package() == nullptr); } TEST_CASE("compare null versions", M) { - REQUIRE(Version("0-beta") > Version()); - REQUIRE(Version("0") > Version()); - REQUIRE(Version("0") != Version()); - REQUIRE(Version() == Version()); + REQUIRE(VersionName("0-beta") > VersionName()); + REQUIRE(VersionName("0") > VersionName()); + REQUIRE(VersionName("0") != VersionName()); + REQUIRE(VersionName() == VersionName()); } TEST_CASE("parse valid versions", M) { - Version ver; + VersionName ver; SECTION("valid") { ver.parse("1.0.1"); - REQUIRE(ver.name() == "1.0.1"); + REQUIRE(ver.toString() == "1.0.1"); REQUIRE(ver.size() == 3); } @@ -56,7 +54,7 @@ TEST_CASE("parse valid versions", M) { } TEST_CASE("parse invalid versions", M) { - Version ver; + VersionName ver; string name; SECTION("only letters") @@ -76,44 +74,44 @@ TEST_CASE("parse invalid versions", M) { REQUIRE(string(e.what()) == string("invalid version name '") + name + "'"); } - REQUIRE(ver.name().empty()); + REQUIRE(ver.toString().empty()); REQUIRE(ver.size() == 0); } TEST_CASE("parse version failsafe", M) { - Version ver; + VersionName ver; SECTION("valid") { REQUIRE(ver.tryParse("1.0")); - REQUIRE(ver.name() == "1.0"); + REQUIRE(ver.toString() == "1.0"); REQUIRE(ver.size() == 2); } SECTION("invalid") { REQUIRE_FALSE(ver.tryParse("hello")); - REQUIRE(ver.name().empty()); + REQUIRE(ver.toString().empty()); REQUIRE(ver.size() == 0); } } TEST_CASE("decimal version", M) { - Version ver("5.05"); - REQUIRE(ver == Version("5.5")); - REQUIRE(ver < Version("5.50")); + VersionName ver("5.05"); + REQUIRE(ver == VersionName("5.5")); + REQUIRE(ver < VersionName("5.50")); } TEST_CASE("5 version segments", M) { - REQUIRE(Version("1.1.1.1.0") < Version("1.1.1.1.1")); - REQUIRE(Version("1.1.1.1.1") == Version("1.1.1.1.1")); - REQUIRE(Version("1.1.1.1.1") < Version("1.1.1.1.2")); - REQUIRE(Version("1.1.1.1.1") < Version("1.1.1.2.0")); + REQUIRE(VersionName("1.1.1.1.0") < VersionName("1.1.1.1.1")); + REQUIRE(VersionName("1.1.1.1.1") == VersionName("1.1.1.1.1")); + REQUIRE(VersionName("1.1.1.1.1") < VersionName("1.1.1.1.2")); + REQUIRE(VersionName("1.1.1.1.1") < VersionName("1.1.1.2.0")); } TEST_CASE("version segment overflow", M) { try { - Version ver("9999999999999999999999"); + VersionName ver("9999999999999999999999"); FAIL(); } catch(const reapack_error &e) { @@ -123,72 +121,81 @@ TEST_CASE("version segment overflow", M) { TEST_CASE("compare versions", M) { SECTION("equality") { - REQUIRE(Version("1.0").compare(Version("1.0")) == 0); + REQUIRE(VersionName("1.0").compare({"1.0"}) == 0); - REQUIRE(Version("1.0") == Version("1.0")); - REQUIRE_FALSE(Version("1.0") == Version("1.1")); + REQUIRE(VersionName("1.0") == VersionName("1.0")); + REQUIRE_FALSE(VersionName("1.0") == VersionName("1.1")); } SECTION("inequality") { - REQUIRE_FALSE(Version("1.0") != Version("1.0")); - REQUIRE(Version("1.0") != Version("1.1")); + REQUIRE_FALSE(VersionName("1.0") != VersionName("1.0")); + REQUIRE(VersionName("1.0") != VersionName("1.1")); } SECTION("less than") { - REQUIRE(Version("1.0").compare(Version("1.1")) == -1); + REQUIRE(VersionName("1.0").compare({"1.1"}) == -1); - REQUIRE(Version("1.0") < Version("1.1")); - REQUIRE_FALSE(Version("1.0") < Version("1.0")); - REQUIRE_FALSE(Version("1.1") < Version("1.0")); + REQUIRE(VersionName("1.0") < VersionName("1.1")); + REQUIRE_FALSE(VersionName("1.0") < VersionName("1.0")); + REQUIRE_FALSE(VersionName("1.1") < VersionName("1.0")); } SECTION("less than or equal") { - REQUIRE(Version("1.0") <= Version("1.1")); - REQUIRE(Version("1.0") <= Version("1.0")); - REQUIRE_FALSE(Version("1.1") <= Version("1.0")); + REQUIRE(VersionName("1.0") <= VersionName("1.1")); + REQUIRE(VersionName("1.0") <= VersionName("1.0")); + REQUIRE_FALSE(VersionName("1.1") <= VersionName("1.0")); } SECTION("greater than") { - REQUIRE(Version("1.1").compare(Version("1.0")) == 1); + REQUIRE(VersionName("1.1").compare({"1.0"}) == 1); - REQUIRE_FALSE(Version("1.0") > Version("1.1")); - REQUIRE_FALSE(Version("1.0") > Version("1.0")); - REQUIRE(Version("1.1") > Version("1.0")); + REQUIRE_FALSE(VersionName("1.0") > VersionName("1.1")); + REQUIRE_FALSE(VersionName("1.0") > VersionName("1.0")); + REQUIRE(VersionName("1.1") > VersionName("1.0")); } SECTION("greater than or equal") { - REQUIRE_FALSE(Version("1.0") >= Version("1.1")); - REQUIRE(Version("1.0") >= Version("1.0")); - REQUIRE(Version("1.1") >= Version("1.0")); + REQUIRE_FALSE(VersionName("1.0") >= VersionName("1.1")); + REQUIRE(VersionName("1.0") >= VersionName("1.0")); + REQUIRE(VersionName("1.1") >= VersionName("1.0")); } } TEST_CASE("compare versions with more or less segments", M) { - REQUIRE(Version("1") == Version("1.0.0.0")); - REQUIRE(Version("1") != Version("1.0.0.1")); + REQUIRE(VersionName("1") == VersionName("1.0.0.0")); + REQUIRE(VersionName("1") != VersionName("1.0.0.1")); - REQUIRE(Version("1.0.0.0") == Version("1")); - REQUIRE(Version("1.0.0.1") != Version("1")); + REQUIRE(VersionName("1.0.0.0") == VersionName("1")); + REQUIRE(VersionName("1.0.0.1") != VersionName("1")); } TEST_CASE("prerelease versions", M) { SECTION("detect") { - REQUIRE(Version("1.0").isStable()); - REQUIRE_FALSE(Version("1.0b").isStable()); - REQUIRE_FALSE(Version("1.0-beta").isStable()); - REQUIRE_FALSE(Version("1.0-beta1").isStable()); + REQUIRE(VersionName("1.0").isStable()); + REQUIRE_FALSE(VersionName("1.0b").isStable()); + REQUIRE_FALSE(VersionName("1.0-beta").isStable()); + REQUIRE_FALSE(VersionName("1.0-beta1").isStable()); } SECTION("compare") { - REQUIRE(Version("0.9") < Version("1.0a")); - REQUIRE(Version("1.0a.2") < Version("1.0b.1")); - REQUIRE(Version("1.0-beta1") < Version("1.0")); + REQUIRE(VersionName("0.9") < VersionName("1.0a")); + REQUIRE(VersionName("1.0a.2") < VersionName("1.0b.1")); + REQUIRE(VersionName("1.0-beta1") < VersionName("1.0")); - REQUIRE(Version("1.0b") < Version("1.0.1")); - REQUIRE(Version("1.0.1") > Version("1.0b")); + REQUIRE(VersionName("1.0b") < VersionName("1.0.1")); + REQUIRE(VersionName("1.0.1") > VersionName("1.0b")); } } +TEST_CASE("copy version constructor", M) { + const VersionName original("1.1test"); + const VersionName copy(original); + + REQUIRE(copy.toString() == "1.1test"); + REQUIRE(copy.size() == original.size()); + REQUIRE(copy.isStable() == original.isStable()); +} + TEST_CASE("version full name", M) { Index ri("Index Name"); Category cat("Category Name", &ri); @@ -264,9 +271,14 @@ TEST_CASE("drop sources for unknown platforms", M) { TEST_CASE("version author", M) { Version ver("1.0"); CHECK(ver.author().empty()); + REQUIRE(ver.displayAuthor() == "Unknown"); ver.setAuthor("cfillion"); REQUIRE(ver.author() == "cfillion"); + REQUIRE(ver.displayAuthor() == ver.author()); + + REQUIRE(Version::displayAuthor({}) == "Unknown"); + REQUIRE(Version::displayAuthor("cfillion") == "cfillion"); } TEST_CASE("version date", M) { @@ -278,24 +290,3 @@ TEST_CASE("version date", M) { ver.setTime("hello world"); REQUIRE(ver.time().year() == 2016); } - -TEST_CASE("copy version constructor", M) { - Index ri("Remote Name"); - Category cat("Category Name", &ri); - Package pkg(Package::ScriptType, "Hello", &cat); - - Version original("1.1test", &pkg); - original.setAuthor("John Doe"); - original.setChangelog("Initial release"); - original.setTime("2016-02-12T01:16:40Z"); - - const Version copy(original); - REQUIRE(copy.name() == "1.1test"); - REQUIRE(copy.size() == original.size()); - REQUIRE(copy.isStable() == original.isStable()); - REQUIRE(copy.author() == original.author()); - REQUIRE(copy.changelog().empty()); - REQUIRE_FALSE(copy.time().isValid()); - REQUIRE(copy.package() == nullptr); - REQUIRE(copy.sources().empty()); -}