@@ -190,4 +190,72 @@ void main() {
190190 expect (constraint.allows (Version .parse ('2.0.0-0' )), isFalse);
191191 });
192192 });
193+
194+ group ('intersection()' , () {
195+ test ('of no constraints allows any version' , () {
196+ var constraint = VersionConstraint .intersection ([]);
197+
198+ expect (constraint, equals (VersionConstraint .any));
199+ });
200+
201+ test ('of overlapping ranges is their overlap' , () {
202+ var constraint = VersionConstraint .intersection ([
203+ VersionRange (min: v123, max: v200),
204+ VersionRange (min: v114, max: v140),
205+ ]);
206+
207+ expect (constraint, equals (VersionRange (min: v123, max: v140)));
208+ });
209+
210+ // https://github.com/dart-lang/tools/issues/2608
211+ test ('of disjoint ranges is empty' , () {
212+ var constraint = VersionConstraint .intersection ([
213+ VersionRange (min: v123, max: v140),
214+ VersionRange (min: v200, max: v234),
215+ ]);
216+
217+ expect (constraint.isEmpty, isTrue);
218+ });
219+
220+ test ('of a range and a version it allows is that version' , () {
221+ var constraint =
222+ VersionConstraint .intersection ([VersionRange (max: v200), v123]);
223+
224+ expect (constraint, equals (v123));
225+ });
226+
227+ test ('of a range and a version it does not allow is empty' , () {
228+ var constraint =
229+ VersionConstraint .intersection ([VersionRange (max: v140), v200]);
230+
231+ expect (constraint.isEmpty, isTrue);
232+ });
233+
234+ test ('stays empty once a disjoint constraint is seen' , () {
235+ var constraint = VersionConstraint .intersection ([
236+ VersionRange (min: v123, max: v140),
237+ VersionRange (min: v200, max: v234),
238+ VersionConstraint .any,
239+ ]);
240+
241+ expect (constraint.isEmpty, isTrue);
242+ });
243+
244+ test ('of a range and a union can be a union' , () {
245+ var constraint = VersionConstraint .intersection ([
246+ VersionRange (min: v010, max: v300),
247+ VersionUnion .fromRanges ([
248+ VersionRange (min: v072, max: v123),
249+ VersionRange (min: v200, max: v250),
250+ ]),
251+ ]);
252+
253+ expect (
254+ constraint,
255+ equals (VersionUnion .fromRanges ([
256+ VersionRange (min: v072, max: v123),
257+ VersionRange (min: v200, max: v250),
258+ ])));
259+ });
260+ });
193261}
0 commit comments