1 module dud.semver.setoperationtest;
2 
3 @safe pure private:
4 import std.exception : assertThrown, assertNotThrown;
5 import std.stdio;
6 import std.format : format;
7 
8 import dud.semver.checks;
9 import dud.semver.parse;
10 import dud.semver.semver;
11 import dud.semver.versionrange;
12 import dud.semver.versionunion;
13 import dud.semver.setoperation;
14 
15 import dud.semver.testdata;
16 
17 unittest { // SemVer, SemVer
18 	VersionUnion vu = unionOf(v1, v2);
19 	assert( allowsAll(vu, v1));
20 	assert( allowsAll(vu, v2));
21 	assert(!allowsAll(vu, v3));
22 	assert(!allowsAll(vu, v4));
23 
24 	assert(!allowsAll(vu, vr1));
25 }
26 
27 // VersionRange, SemVer
28 unittest {
29 	const VersionUnion vu = unionOf(vr1, v1);
30 	assert(vu.ranges.length == 2);
31 	assert(vu.ranges[1] == vr1);
32 
33 	assert( allowsAll(vu, v1));
34 	assert( allowsAll(vu, vr1));
35 
36 	const VersionUnion vu2 = unionOf(v1, vr1);
37 }
38 
39 unittest {
40 	const VersionUnion vu = unionOf(vr1, v2);
41 	assert(vu.ranges.length == 1);
42 	assert( allowsAll(vu, v2));
43 	assert( allowsAll(vu, vr1), format("\n%s\n%s", vu, vr1));
44 }
45 
46 unittest {
47 	const all = [vr1, vr2, vr3, vr4, vr5, vr6];
48 	foreach(it; all) {
49 		foreach(jt; all) {
50 			const VersionUnion vu = unionOf(it, jt);
51 			assert(allowsAll(vu, it));
52 			assert(allowsAll(vu, jt));
53 
54 			const SetRelation sr = relation(it, jt);
55 			assert(vu.ranges.length == (sr == SetRelation.disjoint ? 2 : 1),
56 				format("\nit:%s\njt:%s\nrs:%s", it, jt, vu.ranges));
57 
58 			const VersionUnion c = vu.dup();
59 			assert(allowsAll(c, it));
60 			assert(allowsAll(c, jt));
61 		}
62 	}
63 }
64 
65 // VersionUnion, SemVer
66 unittest {
67 	const VersionUnion m = unionOf(vu2, v4);
68 	assert(m.ranges.length == 2);
69 	assert(allowsAll(m, vr1));
70 	assert(allowsAll(m, vr2));
71 	assert(allowsAll(m, v4));
72 
73 	const VersionUnion m2 = unionOf(v4, vu2);
74 	assert(m == m2);
75 }
76 
77 // VersionUnion, VersionRange
78 unittest {
79 	const VersionUnion m = unionOf(vu1, vr6);
80 	assert(m.ranges.length == 1);
81 	assert(allowsAll(m, vu1));
82 	assert(allowsAll(m, vr3));
83 
84 	const VersionUnion m2 = unionOf(vr6, vu1);
85 	assert(m == m2);
86 }
87 
88 // VersionUnion, VersionUnion
89 unittest {
90 	const VersionUnion m = unionOf(vu1, vu2);
91 	assert(m.ranges.length == 2);
92 	assert(allowsAll(m, vr1));
93 	assert(allowsAll(m, vr2));
94 	assert(allowsAll(m, vr4));
95 }