Skip to content

Commit

Permalink
Test registry: Store version separate from Package
Browse files Browse the repository at this point in the history
This will allow us to store full packages (FSEntry) instead of
the processed / already instantiated Package.
  • Loading branch information
Geod24 committed Feb 22, 2024
1 parent fc93c40 commit ef49c85
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ package class TestPackageManager : PackageManager
public class MockPackageSupplier : PackageSupplier
{
/// Mapping of package name to packages, ordered by `Version`
protected Package[][PackageName] pkgs;
protected Package[Version][PackageName] pkgs;

/// URL this was instantiated with
protected string url;
Expand All @@ -499,7 +499,7 @@ public class MockPackageSupplier : PackageSupplier
public override Version[] getVersions(in PackageName name)
{
if (auto ppkgs = name.main in this.pkgs)
return (*ppkgs).map!(pkg => pkg.version_).array;
return (*ppkgs).keys;
return null;
}

Expand All @@ -517,12 +517,14 @@ public class MockPackageSupplier : PackageSupplier
{
import dub.recipe.json;

Package match;
if (auto ppkgs = name.main in this.pkgs)
foreach_reverse (pkg; *ppkgs)
if ((!pkg.version_.isPreRelease || pre_release) &&
dep.matches(pkg.version_))
return toJson(pkg.recipe);
return Json.init;
foreach (vers, pkg; *ppkgs)
if ((!vers.isPreRelease || pre_release) &&
dep.matches(vers) &&
(match is null || match.version_ < vers))
match = pkg;
return match is null ? Json.init : toJson(match.recipe);
}

///
Expand Down

0 comments on commit ef49c85

Please sign in to comment.