deno.land / std@0.224.0 / semver / range_intersects_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { parseRange } from "./parse_range.ts";import { rangeIntersects } from "./range_intersects.ts";
Deno.test({ name: "rangesIntersects()", fn: async (t) => { const versions: [string, string, boolean][] = [ ["1.3.0 || <1.0.0 >2.0.0", "1.3.0 || <1.0.0 >2.0.0", true], [">0.0.0", "<1.0.0 >2.0.0", false], ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0", false], ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], [">1.0.0 <=2.0.0", "2.0.0", true], ["<1.0.0 >=2.0.0", "2.1.0", false], ["<1.0.0 >=2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], ["1.5.x", "<1.5.0 || >=1.6.0", false], ["<1.5.0 || >=1.6.0", "1.5.x", false], [ "<1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", false, ], [ "<=1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", true, ], [">=1.0.0", "<=1.0.0", true], [">1.0.0 <1.0.0", "<=0.0.0", false], // Pre-release ranges ["<1.0.0", ">1.0.0-5", true], [">1.0.0", "<1.0.0-5", false], [">1.0.0-2", "<=1.0.0-5", true], [">=1.0.0-2", "<1.0.0-5", true], ["<7.0.0-beta.20", ">7.0.0-beta.0", true], ["<7.0.0-beta.beta", ">7.0.0-beta.alpha", true], // Wildcards ["*", "0.0.1", true], ["*", ">=1.0.0", true], ["*", ">1.0.0", true], ["*", "~1.0.0", true], ["*", "<1.6.0", true], ["*", "<=1.6.0", true], ["1.*", "0.0.1", false], ["1.*", "2.0.0", false], ["1.*", "1.0.0", true], ["1.*", "<2.0.0", true], ["1.*", ">1.0.0", true], ["1.*", "<=1.0.0", true], ["1.*", "^1.0.0", true], ["1.0.*", "0.0.1", false], ["1.0.*", "<0.0.1", false], ["1.0.*", ">0.0.1", true], ["*", "1.3.0 || <1.0.0 >2.0.0", true], ["1.3.0 || <1.0.0 >2.0.0", "*", true], ["1.*", "1.3.0 || <1.0.0 >2.0.0", true], ["x", "0.0.1", true], ["x", ">=1.0.0", true], ["x", ">1.0.0", true], ["x", "~1.0.0", true], ["x", "<1.6.0", true], ["x", "<=1.6.0", true], ["1.x", "0.0.1", false], ["1.x", "2.0.0", false], ["1.x", "1.0.0", true], ["1.x", "<2.0.0", true], ["1.x", ">1.0.0", true], ["1.x", "<=1.0.0", true], ["1.x", "^1.0.0", true], ["1.0.x", "0.0.1", false], ["1.0.x", "<0.0.1", false], ["1.0.x", ">0.0.1", true], ["x", "1.3.0 || <1.0.0 >2.0.0", true], ["1.3.0 || <1.0.0 >2.0.0", "x", true], ["1.x", "1.3.0 || <1.0.0 >2.0.0", true], ["*", "*", true], ["x", "", true],
// One is a Version ["1.3.0", ">=1.3.0", true], ["1.3.0", ">1.3.0", false], [">=1.3.0", "1.3.0", true], [">1.3.0", "1.3.0", false],
// Same direction increasing [">1.3.0", ">1.2.0", true], [">1.2.0", ">1.3.0", true], [">=1.2.0", ">1.3.0", true], [">1.2.0", ">=1.3.0", true],
// Same direction decreasing ["<1.3.0", "<1.2.0", true], ["<1.2.0", "<1.3.0", true], ["<=1.2.0", "<1.3.0", true], ["<1.2.0", "<=1.3.0", true],
// Different directions, same semver and inclusive operator [">=1.3.0", "<=1.3.0", true], [">=v1.3.0", "<=1.3.0", true], [">=1.3.0", ">=1.3.0", true], ["<=1.3.0", "<=1.3.0", true], ["<=1.3.0", "<=v1.3.0", true], [">1.3.0", "<=1.3.0", false], [">=1.3.0", "<1.3.0", false],
// Opposite matching directions [">1.0.0", "<2.0.0", true], [">=1.0.0", "<2.0.0", true], [">=1.0.0", "<=2.0.0", true], [">1.0.0", "<=2.0.0", true], ["<=2.0.0", ">1.0.0", true], ["<=1.0.0", ">=2.0.0", false], ];
for (const [r1, r2, expected] of versions) { await t.step({ name: `${r1} ∩ ${r2}`, fn: () => { const range1 = parseRange(r1); const range2 = parseRange(r2); const actual1 = rangeIntersects(range1, range2); const actual2 = rangeIntersects(range2, range1); assertEquals(actual1, expected); assertEquals(actual2, expected); }, }); } },});
Version Info