1 module dud.resolve.term; 2 3 __EOF__ 4 5 import std.exception : enforce; 6 7 import dud.pkgdescription; 8 import dud.semver.versionrange : SetRelation; 9 import dud.resolve.versionconfiguration : invert, VersionConfiguration; 10 import dud.resolve.providier; 11 import dud.resolve.positive; 12 import dud.resolve.conf; 13 import dud.resolve.confs; 14 15 @safe pure: 16 struct Term { 17 VersionConfiguration constraint; 18 PackageDescriptionVersionRange pkg; 19 20 /// is only an indicator `contraint` is used to store both stats 21 IsPositive isPositive; 22 } 23 24 Term invert(const(Term) t) { 25 VersionConfiguration vc = t.constraint.invert(); 26 return Term(vc, t.pkg.dup(), cast(IsPositive)!t.isPositive); 27 } 28 29 bool satisfies(const(Term) that, const(Term) other) { 30 return that.pkg.pkg.name == other.pkg.pkg.name 31 && relation(other, that) == SetRelation.subset; 32 } 33 34 unittest { 35 import dud.semver.versionrange; 36 import dud.semver.versionunion; 37 import dud.semver.checks; 38 39 Term t1; 40 t1.pkg.ver = parseVersionRange("1.2.3").get(); 41 t1.isPositive = IsPositive.yes; 42 t1.constraint = VersionConfiguration( 43 VersionUnion([ parseVersionRange(">=1.0.0").get() ]), 44 Confs([Conf("", IsPositive.yes)]) 45 ); 46 47 Term t2 = t1.invert(); 48 assert(!allowsAny(t1.constraint.ver, t2.constraint.ver)); 49 } 50 51 SetRelation relation(const(Term) a, const(Term) b) { 52 static import dud.resolve.versionconfiguration; 53 enforce(a.pkg.pkg.name == b.pkg.pkg.name); 54 return dud.resolve.versionconfiguration.relation(a.constraint, b.constraint); 55 }