1 module dud.semver.checks;
2 
3 import std.algorithm.searching : all, any;
4 
5 import dud.semver.versionunion;
6 import dud.semver.versionrange;
7 import dud.semver.semver;
8 
9 @safe pure:
10 
11 /// Returns `true` if this constraint allows [version].
12 bool allowsAny(const(VersionRange) toCheckIn, const(SemVer) toCheck) {
13 	return isInRange(toCheckIn, toCheck);
14 }
15 
16 bool allowsAny(const(VersionRange) toCheckIn, const(VersionRange) toCheck) {
17 	const SetRelation sr = relation(toCheck, toCheckIn);
18 	return sr != SetRelation.disjoint;
19 }
20 
21 bool allowsAny(const(VersionRange) toCheckIn, const(VersionUnion) toCheck) {
22 	return toCheck.ranges
23 		.any!(vr => relation(vr, toCheckIn) != SetRelation.disjoint);
24 }
25 
26 bool allowsAny(const(VersionUnion) toCheckIn, const(SemVer) toCheck) {
27 	return toCheckIn.ranges.any!(vr => isInRange(vr, toCheck));
28 }
29 
30 bool allowsAny(const(VersionUnion) toCheckIn, const(VersionRange) toCheck) {
31 	return toCheckIn.ranges
32 		.any!(vr => relation(toCheck, vr) != SetRelation.disjoint);
33 }
34 
35 bool allowsAny(const(VersionUnion) toCheckIn, const(VersionUnion) toCheck) {
36 	foreach(it; toCheck.ranges) {
37 		foreach(jt; toCheckIn.ranges) {
38 			const SetRelation sr = relation(it, jt);
39 			if(sr != SetRelation.disjoint) {
40 				return true;
41 			}
42 		}
43 	}
44 	return false;
45 }
46 
47 /// Returns `true` if this constraint allows all the versions that [other]
48 /// allows.
49 bool allowsAll(const(VersionRange) toCheckIn, const(SemVer) toCheck) {
50 	return isInRange(toCheckIn, toCheck);
51 }
52 
53 bool allowsAll(const(VersionRange) toCheckIn, const(VersionRange) toCheck) {
54 	return relation(toCheck, toCheckIn) == SetRelation.subset;
55 }
56 
57 bool allowsAll(const(VersionRange) toCheckIn, const(VersionUnion) toCheck) {
58 	return toCheck.ranges
59 		.all!(vr => relation(vr, toCheckIn) == SetRelation.subset);
60 }
61 
62 bool allowsAll(const(VersionUnion) toCheckIn, const(SemVer) toCheck) {
63 	return toCheckIn.ranges.any!(vr => isInRange(vr, toCheck));
64 }
65 
66 bool allowsAll(const(VersionUnion) toCheckIn, const(VersionRange) toCheck) {
67 	return toCheckIn.ranges
68 		.any!(vr => relation(toCheck, vr) == SetRelation.subset);
69 }
70 
71 bool allowsAll(const(VersionUnion) toCheckIn, const(VersionUnion) toCheck) {
72 	outer: foreach(it; toCheck.ranges) {
73 		foreach(jt; toCheckIn.ranges) {
74 			const SetRelation sr = relation(it, jt);
75 			if(sr == SetRelation.subset) {
76 				continue outer;
77 			}
78 		}
79 		return false;
80 	}
81 	return true;
82 }