reapack

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

commit 3aa09201e95fced07cb9b5a54d88b117fd31546d
parent ffce6ed347d5261eeac7dbeb3817afcfc2be118d
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 21 Aug 2016 23:26:18 -0400

refactor obsolete package detection

Diffstat:
Msrc/browser.cpp | 4+---
Msrc/index.cpp | 8++++++++
Msrc/index.hpp | 1+
Mtest/index.cpp | 17+++++++++++++++++
4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -567,9 +567,7 @@ void Browser::populate() // obsolete packages for(const Registry::Entry &regEntry : reg.getEntries(index->name())) { - const Category *cat = index->category(regEntry.category); - - if(!cat || !cat->package(regEntry.package)) + if(!index->find(regEntry.category, regEntry.package)) m_entries.push_back({InstalledFlag | ObsoleteFlag, regEntry}); } } diff --git a/src/index.cpp b/src/index.cpp @@ -145,6 +145,14 @@ const Category *Index::category(const string &name) const return category(it->second); } +const Package *Index::find(const string &catName, const string &pkgName) const +{ + if(const Category *cat = category(catName)) + return cat->package(pkgName); + else + return nullptr; +} + Category::Category(const string &name, const Index *ri) : m_index(ri), m_name(name) { diff --git a/src/index.hpp b/src/index.hpp @@ -59,6 +59,7 @@ public: const CategoryList &categories() const { return m_categories; } const Category *category(size_t i) const { return m_categories[i]; } const Category *category(const std::string &name) const; + const Package *find(const std::string &cat, const std::string &pkg) const; const PackageList &packages() const { return m_packages; } diff --git a/test/index.cpp b/test/index.cpp @@ -217,3 +217,20 @@ TEST_CASE("set index name", M) { REQUIRE(ri.name() == "hello"); } } + +TEST_CASE("find package", M) { + Index ri("index name"); + Category *cat = new Category("cat", &ri); + Package *pack = new Package(Package::ScriptType, "pkg", cat); + Version *ver = new Version("1", pack); + Source *source = new Source({}, "google.com", ver); + + ver->addSource(source); + pack->addVersion(ver); + cat->addPackage(pack); + ri.addCategory(cat); + + REQUIRE(ri.find("a", "b") == nullptr); + REQUIRE(ri.find("cat", "b") == nullptr); + REQUIRE(ri.find("cat", "pkg") == pack); +}