1 module dud.semver.versionuniontest;
2 
3 @safe pure private:
4 import std.array : front;
5 import std.format : format;
6 import std.stdio;
7 
8 import dud.semver.semver;
9 import dud.semver.parse;
10 import dud.semver.versionrange;
11 import dud.semver.versionunion;
12 import dud.semver.comparision;
13 
14 unittest {
15 	VersionRange vr1 = parseVersionRange(">=1.0.0 <=2.0.0").get();
16 	VersionRange vr2 = parseVersionRange(">=1.5.0 <=3.0.0").get();
17 
18 	VersionRange m = merge(vr1, vr2);
19 	SetRelation sr = relation(m, parseVersionRange(">=1.0.0 <=3.0.0").get());
20 	assert(sr == SetRelation.subset, format("\nm: %s\nsr: %s", m, sr));
21 
22 	m = merge(vr2, vr1);
23 	sr = relation(m, parseVersionRange(">=1.0.0 <=3.0.0").get());
24 	assert(sr == SetRelation.subset, format("\nm: %s\nsr: %s", m, sr));
25 }
26 
27 unittest {
28 	VersionRange vr1 = parseVersionRange(">=1.0.0 <=1.5.0").get();
29 	VersionRange vr2 = parseVersionRange(">=1.5.0 <=3.0.0").get();
30 
31 	VersionRange m = merge(vr1, vr2);
32 	SetRelation sr = relation(m, parseVersionRange(">=1.0.0 <=3.0.0").get());
33 	assert(sr == SetRelation.subset, format("\nm: %s\nsr: %s", m, sr));
34 
35 	m = merge(vr2, vr1);
36 	sr = relation(m, parseVersionRange(">=1.0.0 <=3.0.0").get());
37 	assert(sr == SetRelation.subset, format("\nm: %s\nsr: %s", m, sr));
38 }
39 
40 unittest {
41 	VersionRange vr1 = parseVersionRange(">=1.0.0 <1.5.0").get();
42 	VersionRange vr2 = parseVersionRange(">1.5.0 <=3.0.0").get();
43 
44 	VersionRange m = merge(vr1, vr2);
45 	assert(m == VersionRange.init, format("\n%s", m));
46 
47 	m = merge(vr2, vr1);
48 	assert(m == VersionRange.init, format("\n%s", m));
49 }
50 
51 unittest {
52 	VersionRange vr1 = parseVersionRange(">=1.0.0 <=1.5.0").get();
53 	VersionRange vr2 = parseVersionRange(">1.5.0 <=3.0.0").get();
54 
55 	VersionRange m = merge(vr1, vr2);
56 	assert(m == VersionRange.init, format("\n%s", m));
57 
58 	m = merge(vr2, vr1);
59 	assert(m == VersionRange.init, format("\n%s", m));
60 }
61 
62 unittest {
63 	VersionRange[] arr =
64 		[ parseVersionRange(">=1.0.0 <=1.5.0").get()
65 		, parseVersionRange(">=2.0.0 <=3.5.0").get()
66 		];
67 
68 	VersionRange vr = parseVersionRange(">=1.5.0 <=2.0.0").get();
69 	VersionRange[] m = merge(arr, vr);
70 	assert(m.length == 1, format("%s", m));
71 
72 	auto exp = parseVersionRange(">=1.0.0 <=3.5.0").get();
73 	assert(m.front == exp, format("\nexp: %s\ngot: %s", exp, m.front));
74 }
75 
76 unittest {
77 	const VersionRange vr1 = parseVersionRange(">=1.0.0 <=2.0.0").get();
78 	const VersionRange vr2 = parseVersionRange(">=1.5.0 <=3.0.0").get();
79 	const VersionRange vr3 = parseVersionRange(">=3.5.0 <=4.0.0").get();
80 	const VersionRange vr4 = parseVersionRange(">=4.5.0 <=5.0.0").get();
81 	const VersionRange vr5 = parseVersionRange(">=3.0.0 <=3.5.0").get();
82 	const VersionRange vr6 = parseVersionRange(">=4.0.0 <=4.5.0").get();
83 
84 	VersionUnion vu;
85 	vu.insert(vr1);
86 	vu.insert(vr2);
87 	assert(vu.ranges.length == 1);
88 	vu.insert(vr3);
89 	assert(vu.ranges.length == 2);
90 	vu.insert(vr4);
91 	assert(vu.ranges.length == 3);
92 	vu.insert(vr5);
93 	assert(vu.ranges.length == 2);
94 	vu.insert(vr6);
95 	assert(vu.ranges.length == 1);
96 }
97 
98 unittest {
99 	const VersionRange vr1 = parseVersionRange(">=1.0.0 <2.0.0").get();
100 	const VersionRange vr2 = parseVersionRange(">2.0.0 <=3.0.0").get();
101 
102 	const VersionUnion vu1 = VersionUnion([vr1, vr2]);
103 	assert(vu1.ranges.length == 2);
104 	assert(vu1.ranges[0] == vr1);
105 	assert(vu1.ranges[1] == vr2);
106 }