1 module dud.semver.setoperationtest2; 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 immutable SemVer v1 = SemVer(1,0,0); 16 immutable SemVer v2 = SemVer(2,0,0); 17 immutable SemVer v3 = SemVer(3,0,0); 18 immutable SemVer v4 = SemVer(4,0,0); 19 immutable SemVer v5 = SemVer(5,0,0); 20 21 immutable VersionRange vr1 = VersionRange(v1, Inclusive.yes, v2, Inclusive.yes); 22 immutable VersionRange vr2 = VersionRange(v2, Inclusive.yes, v3, Inclusive.yes); 23 immutable VersionRange vr3 = VersionRange(v3, Inclusive.yes, v4, Inclusive.yes); 24 immutable VersionRange vr4 = VersionRange(v1, Inclusive.yes, v3, Inclusive.yes); 25 immutable VersionRange vr5 = VersionRange(v2, Inclusive.yes, v5, Inclusive.yes); 26 27 // 28 // invert 29 // 30 31 // SemVer 32 unittest { 33 const VersionUnion r = invert(v1); 34 assert(r.ranges.length == 2); 35 36 assert(r.ranges[0] == 37 VersionRange(SemVer.min, Inclusive.yes, v1, Inclusive.no)); 38 39 assert(r.ranges[1] == 40 VersionRange(v1, Inclusive.no, SemVer.max, Inclusive.yes)); 41 } 42 43 // VersionRange 44 unittest { 45 const VersionUnion r = invert(vr1); 46 assert(r.ranges.length == 2); 47 assert(r.ranges[0] == 48 VersionRange(SemVer.min(), Inclusive.yes, vr1.low.dup, 49 cast(Inclusive)!vr1.inclusiveLow)); 50 assert(r.ranges[1] == 51 VersionRange(vr1.high.dup, cast(Inclusive)!vr1.inclusiveHigh, 52 SemVer.max(), Inclusive.yes), format("%s", r.ranges[1])); 53 } 54 55 // VersionUnion 56 unittest { 57 const VersionUnion vu = VersionUnion([vr1, vr3]); 58 const VersionUnion r = invert(vu); 59 assert(r.ranges.length == 3); 60 assert(r.ranges[0] == 61 VersionRange(SemVer.min(), Inclusive.yes, v1, Inclusive.no), 62 format("%s", r.ranges[0])); 63 assert(r.ranges[1] == 64 VersionRange(v2, Inclusive.no, v3, Inclusive.no), 65 format("%s", r.ranges[1])); 66 assert(r.ranges[2] == 67 VersionRange(v4, Inclusive.no, SemVer.max(), Inclusive.yes), 68 format("%s", r.ranges[2])); 69 } 70 71 unittest { 72 const VersionUnion vu = VersionUnion([]); 73 const VersionUnion r = invert(vu); 74 assert(r.ranges.length == 1); 75 assert(r.ranges[0] == VersionRange(SemVer.min(), Inclusive.yes, 76 SemVer.max(), Inclusive.yes)); 77 } 78 79 // 80 // differenceOf 81 // 82 83 // SemVer, SemVer 84 unittest { 85 SemVer r = differenceOf(v1, v1); 86 assert(r == SemVer.init); 87 88 r = differenceOf(v1, v2); 89 assert(r == v1, format("%s", r)); 90 } 91 92 // VersionRange, Semver 93 unittest { 94 const VersionUnion d1 = differenceOf(vr4, v2); 95 assert(d1.ranges.length == 2, format("%s", d1.ranges.length)); 96 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v2, Inclusive.no)); 97 assert(d1.ranges[1] == VersionRange(v2, Inclusive.no, v3, Inclusive.yes)); 98 } 99 100 // SemVer, VersionRange 101 unittest { 102 const SemVer d1 = differenceOf(v2, vr4); 103 assert(d1 == SemVer.init); 104 } 105 106 unittest { 107 const SemVer d1 = differenceOf(v1, vr5); 108 assert(d1 == v1); 109 } 110 111 // VersionRange, VersionRange 112 unittest { 113 const VersionUnion d1 = differenceOf(vr4, vr2); 114 assert(d1.ranges.length == 1); 115 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v2, Inclusive.no)); 116 } 117 118 unittest { 119 const VersionUnion d1 = differenceOf(vr1, vr3); 120 assert(d1.ranges.length == 1); 121 assert(d1.ranges[0] == vr1); 122 } 123 124 unittest { 125 const VersionUnion d1 = differenceOf(vr1, vr1); 126 assert(d1.ranges.length == 0); 127 } 128 129 unittest { 130 const VersionUnion d1 = differenceOf(vr2, vr1); 131 assert(d1.ranges.length == 1); 132 assert(d1.ranges[0] == VersionRange(v2, Inclusive.no, v3, Inclusive.yes)); 133 } 134 135 // VersionUnion, VersionRange 136 unittest { 137 const VersionUnion vu1 = VersionUnion([vr1, vr2]); 138 const VersionUnion d1 = differenceOf(vu1, vr3); 139 140 assert(d1.ranges.length == 1); 141 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v3, Inclusive.no)); 142 } 143 144 unittest { 145 const VersionUnion vu1 = VersionUnion([vr1, vr2, vr3]); 146 const VersionUnion d1 = differenceOf(vu1, vr2); 147 148 assert(d1.ranges.length == 2); 149 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v2, Inclusive.no)); 150 assert(d1.ranges[1] == VersionRange(v3, Inclusive.no, v4, Inclusive.yes)); 151 } 152 153 // VersionRange, VersionUnion 154 unittest { 155 const VersionUnion vu1 = VersionUnion([vr1, vr2, vr3]); 156 const VersionUnion d1 = differenceOf(vr2, vu1); 157 158 assert(d1.ranges.length == 0); 159 } 160 161 unittest { 162 const VersionUnion vu1 = VersionUnion([vr1, vr3]); 163 const VersionUnion d1 = differenceOf(vr2, vu1); 164 165 assert(d1.ranges.length == 1); 166 assert(d1.ranges[0] == VersionRange(v2, Inclusive.no, v3, Inclusive.no)); 167 } 168 169 unittest { 170 const VersionUnion vu1 = VersionUnion([vr3]); 171 const VersionUnion d1 = differenceOf(vr1, vu1); 172 173 assert(d1.ranges.length == 1); 174 assert(d1.ranges[0] == vr1); 175 } 176 177 // VersionUnion, VersionUnion 178 unittest { 179 const VersionUnion vu1 = VersionUnion([vr1, vr2]); 180 const VersionUnion vu2 = VersionUnion([vr2, vr3]); 181 const VersionUnion d1 = differenceOf(vu1, vu2); 182 183 assert(d1.ranges.length == 1); 184 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v2, Inclusive.no)); 185 } 186 187 unittest { 188 const VersionUnion vu1 = VersionUnion([vr1, vr2]); 189 const VersionUnion vu2 = VersionUnion([vr3]); 190 const VersionUnion d1 = differenceOf(vu1, vu2); 191 192 assert(d1.ranges.length == 1); 193 assert(d1.ranges[0] == VersionRange(v1, Inclusive.yes, v3, Inclusive.no)); 194 }