Upstream npm/node-semver state of the touched files before f6bf826ecc
This commit is contained in:
commit
d4354cc38b
3 files changed
+856
No files matched your search
@@ -0,0 +1,128 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const Range = require('../../classes/range')
|
||||
const Comparator = require('../../classes/comparator')
|
||||
const rangeIntersection = require('../fixtures/range-intersection.js')
|
||||
|
||||
const rangeInclude = require('../fixtures/range-include.js')
|
||||
const rangeExclude = require('../fixtures/range-exclude.js')
|
||||
const rangeParse = require('../fixtures/range-parse.js')
|
||||
|
||||
test('range tests', t => {
|
||||
t.plan(rangeInclude.length)
|
||||
rangeInclude.forEach(([range, ver, options]) => {
|
||||
const r = new Range(range, options)
|
||||
t.ok(r.test(ver), `${range} satisfied by ${ver}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('range parsing', t => {
|
||||
t.plan(rangeParse.length)
|
||||
rangeParse.forEach(([range, expect, options]) =>
|
||||
t.test(`${range} ${expect} ${JSON.stringify(options)}`, t => {
|
||||
if (expect === null) {
|
||||
t.throws(() => new Range(range, options), TypeError, `invalid range: ${range}`)
|
||||
} else {
|
||||
t.equal(new Range(range, options).range || '*', expect, `${range} => ${expect}`)
|
||||
t.equal(new Range(range, options).range, new Range(expect).range,
|
||||
'parsing both yields same result')
|
||||
}
|
||||
t.end()
|
||||
}))
|
||||
})
|
||||
|
||||
test('throw for empty comparator set, even in loose mode', t => {
|
||||
t.throws(() => new Range('sadf||asdf', { loose: true }),
|
||||
TypeError('Invalid SemVer Range: sadf||asdf'))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('convert comparator to range', t => {
|
||||
const c = new Comparator('>=1.2.3')
|
||||
const r = new Range(c)
|
||||
t.equal(r.raw, c.value, 'created range from comparator')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('range as argument to range ctor', t => {
|
||||
const loose = new Range('1.2.3', { loose: true })
|
||||
t.equal(new Range(loose, { loose: true }), loose, 'loose option')
|
||||
t.equal(new Range(loose, true), loose, 'loose boolean')
|
||||
t.not(new Range(loose), loose, 'created new range if not matched')
|
||||
|
||||
const incPre = new Range('1.2.3', { includePrerelease: true })
|
||||
t.equal(new Range(incPre, { includePrerelease: true }), incPre,
|
||||
'include prerelease, option match returns argument')
|
||||
t.not(new Range(incPre), incPre,
|
||||
'include prerelease, option mismatch does not return argument')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('negative range tests', t => {
|
||||
t.plan(rangeExclude.length)
|
||||
rangeExclude.forEach(([range, ver, options]) => {
|
||||
const r = new Range(range, options)
|
||||
t.notOk(r.test(ver), `${range} not satisfied by ${ver}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('strict vs loose ranges', (t) => {
|
||||
[
|
||||
['>=01.02.03', '>=1.2.3'],
|
||||
['~1.02.03beta', '>=1.2.3-beta <1.3.0-0'],
|
||||
].forEach(([loose, comps]) => {
|
||||
t.throws(() => new Range(loose))
|
||||
t.equal(new Range(loose, true).range, comps)
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('tostrings', (t) => {
|
||||
t.equal(new Range('>= v1.2.3').toString(), '>=1.2.3')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('formatted value is calculated lazily and cached', (t) => {
|
||||
const r = new Range('>= v1.2.3')
|
||||
t.equal(r.formatted, undefined)
|
||||
t.equal(r.format(), '>=1.2.3')
|
||||
t.equal(r.formatted, '>=1.2.3')
|
||||
t.equal(r.format(), '>=1.2.3')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('ranges intersect', (t) => {
|
||||
rangeIntersection.forEach(([r0, r1, expect]) => {
|
||||
t.test(`${r0} <~> ${r1}`, t => {
|
||||
const range0 = new Range(r0)
|
||||
const range1 = new Range(r1)
|
||||
|
||||
t.equal(range0.intersects(range1), expect,
|
||||
`${r0} <~> ${r1} objects`)
|
||||
t.equal(range1.intersects(range0), expect,
|
||||
`${r1} <~> ${r0} objects`)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('missing range parameter in range intersect', (t) => {
|
||||
t.throws(() => {
|
||||
new Range('1.0.0').intersects()
|
||||
}, new TypeError('a Range is required'),
|
||||
'throws type error')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('cache', (t) => {
|
||||
const cached = Symbol('cached')
|
||||
const r1 = new Range('1.0.0')
|
||||
r1.set[0][cached] = true
|
||||
const r2 = new Range('1.0.0')
|
||||
t.equal(r1.set[0][cached], true)
|
||||
t.equal(r2.set[0][cached], true) // Will be true, showing it's cached.
|
||||
t.end()
|
||||
})
|
||||
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
'use strict'
|
||||
|
||||
// [range, canonical result, options]
|
||||
// null result means it's not a valid range
|
||||
// '*' is the return value from functions.validRange(), but
|
||||
// new Range().range will be '' in those cases
|
||||
const { MAX_SAFE_INTEGER } = require('../../internal/constants')
|
||||
module.exports = [
|
||||
['1.0.0 - 2.0.0', '>=1.0.0 <=2.0.0'],
|
||||
['1.0.0 - 2.0.0', '>=1.0.0-0 <2.0.1-0', { includePrerelease: true }],
|
||||
['1 - 2', '>=1.0.0 <3.0.0-0'],
|
||||
['1 - 2', '>=1.0.0-0 <3.0.0-0', { includePrerelease: true }],
|
||||
['1.0 - 2.0', '>=1.0.0 <2.1.0-0'],
|
||||
['1.0 - 2.0', '>=1.0.0-0 <2.1.0-0', { includePrerelease: true }],
|
||||
['1.0.0', '1.0.0', { loose: false }],
|
||||
['>=*', '*'],
|
||||
['', '*'],
|
||||
['*', '*'],
|
||||
['>=1.0.0', '>=1.0.0'],
|
||||
['>1.0.0', '>1.0.0'],
|
||||
['<=2.0.0', '<=2.0.0'],
|
||||
['1', '>=1.0.0 <2.0.0-0'],
|
||||
['<2.0.0', '<2.0.0'],
|
||||
['>= 1.0.0', '>=1.0.0'],
|
||||
['>= 1.0.0', '>=1.0.0'],
|
||||
['>= 1.0.0', '>=1.0.0'],
|
||||
['> 1.0.0', '>1.0.0'],
|
||||
['> 1.0.0', '>1.0.0'],
|
||||
['<= 2.0.0', '<=2.0.0'],
|
||||
['<= 2.0.0', '<=2.0.0'],
|
||||
['<= 2.0.0', '<=2.0.0'],
|
||||
['< 2.0.0', '<2.0.0'],
|
||||
['<\t2.0.0', '<2.0.0'],
|
||||
['>=0.1.97', '>=0.1.97'],
|
||||
['0.1.20 || 1.2.4', '0.1.20||1.2.4'],
|
||||
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
|
||||
['||', '*'],
|
||||
['2.x.x', '>=2.0.0 <3.0.0-0'],
|
||||
['1.2.x', '>=1.2.0 <1.3.0-0'],
|
||||
['1.2.x || 2.x', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'],
|
||||
['1.x.5', null],
|
||||
['1.*.5', null],
|
||||
['1.x.5 || 2.x', null],
|
||||
['x.1', null],
|
||||
['x.1.2', null],
|
||||
['x.x.1', null],
|
||||
['x', '*'],
|
||||
['2.*.*', '>=2.0.0 <3.0.0-0'],
|
||||
['1.2.*', '>=1.2.0 <1.3.0-0'],
|
||||
['1.2.* || 2.*', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'],
|
||||
['2', '>=2.0.0 <3.0.0-0'],
|
||||
['2.3', '>=2.3.0 <2.4.0-0'],
|
||||
['~2.4', '>=2.4.0 <2.5.0-0'],
|
||||
['~>3.2.1', '>=3.2.1 <3.3.0-0'],
|
||||
['~1', '>=1.0.0 <2.0.0-0'],
|
||||
['~>1', '>=1.0.0 <2.0.0-0'],
|
||||
['~> 1', '>=1.0.0 <2.0.0-0'],
|
||||
['~1.0', '>=1.0.0 <1.1.0-0'],
|
||||
['~ 1.0', '>=1.0.0 <1.1.0-0'],
|
||||
// tilde with includePrerelease must lower-bound at -0 just like the
|
||||
// equivalent x-range (e.g. ~1.2 is documented as the same as 1.2.x),
|
||||
// so that prereleases such as 1.2.0-rc match. See #512.
|
||||
['~1', '>=1.0.0-0 <2.0.0-0', { includePrerelease: true }],
|
||||
['~1.x', '>=1.0.0-0 <2.0.0-0', { includePrerelease: true }],
|
||||
['~1.2', '>=1.2.0-0 <1.3.0-0', { includePrerelease: true }],
|
||||
['~1.2.x', '>=1.2.0-0 <1.3.0-0', { includePrerelease: true }],
|
||||
['~0.0', '<0.1.0-0', { includePrerelease: true }],
|
||||
// a fully-specified tilde keeps its exact lower bound (matches caret),
|
||||
// and an explicit prerelease is preserved as-is
|
||||
['~1.2.3', '>=1.2.3 <1.3.0-0', { includePrerelease: true }],
|
||||
['~1.2.3-beta.4', '>=1.2.3-beta.4 <1.3.0-0', { includePrerelease: true }],
|
||||
['^0', '<1.0.0-0'],
|
||||
['^ 1', '>=1.0.0 <2.0.0-0'],
|
||||
['^0.1', '>=0.1.0 <0.2.0-0'],
|
||||
['^1.0', '>=1.0.0 <2.0.0-0'],
|
||||
['^1.2', '>=1.2.0 <2.0.0-0'],
|
||||
['^0.0.1', '>=0.0.1 <0.0.2-0'],
|
||||
['^0.0.1-beta', '>=0.0.1-beta <0.0.2-0'],
|
||||
['^0.1.2', '>=0.1.2 <0.2.0-0'],
|
||||
['^1.2.3', '>=1.2.3 <2.0.0-0'],
|
||||
['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'],
|
||||
['<1', '<1.0.0-0'],
|
||||
['< 1', '<1.0.0-0'],
|
||||
['>=1', '>=1.0.0'],
|
||||
['>= 1', '>=1.0.0'],
|
||||
['<1.2', '<1.2.0-0'],
|
||||
['< 1.2', '<1.2.0-0'],
|
||||
['>01.02.03', '>1.2.3', true],
|
||||
['>01.02.03', null],
|
||||
['~1.2.3beta', '>=1.2.3-beta <1.3.0-0', { loose: true }],
|
||||
['~1.2.3beta', null],
|
||||
['^ 1.2 ^ 1', '>=1.2.0 <2.0.0-0 >=1.0.0'],
|
||||
['1.2 - 3.4.5', '>=1.2.0 <=3.4.5'],
|
||||
['1.2.3 - 3.4', '>=1.2.3 <3.5.0-0'],
|
||||
['1.2 - 3.4', '>=1.2.0 <3.5.0-0'],
|
||||
['>1', '>=2.0.0'],
|
||||
['>1.2', '>=1.3.0'],
|
||||
['>X', '<0.0.0-0'],
|
||||
['<X', '<0.0.0-0'],
|
||||
['<x <* || >* 2.x', '<0.0.0-0'],
|
||||
['>x 2.x || * || <x', '*'],
|
||||
['>=09090', null],
|
||||
['>=09090', '>=9090.0.0', true],
|
||||
['>=09090-0', null, { includePrerelease: true }],
|
||||
['>=09090-0', null, { loose: true, includePrerelease: true }],
|
||||
[`^${MAX_SAFE_INTEGER}.0.0`, null],
|
||||
[`=${MAX_SAFE_INTEGER}.0.0`, `${MAX_SAFE_INTEGER}.0.0`],
|
||||
[`^${MAX_SAFE_INTEGER - 1}.0.0`, `>=${MAX_SAFE_INTEGER - 1}.0.0 <${MAX_SAFE_INTEGER}.0.0-0`],
|
||||
// x-ranges with build metadata
|
||||
['1.x.x+build >2.x+build', '>=1.0.0 <2.0.0-0 >=3.0.0', null],
|
||||
['>=1.x+build <2.x.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['1.x.x+build || 2.x.x+build', '>=1.0.0 <2.0.0-0||>=2.0.0 <3.0.0-0', null],
|
||||
['1.x+build.123', '>=1.0.0 <2.0.0-0', null],
|
||||
['1.x.x+meta-data', '>=1.0.0 <2.0.0-0', null],
|
||||
['1.x.x+build.123 >2.x.x+meta-data', '>=1.0.0 <2.0.0-0 >=3.0.0', null],
|
||||
['1.x.x+build <2.x.x+meta', '>=1.0.0 <2.0.0-0', null],
|
||||
['>1.x+build <=2.x.x+meta', '>=2.0.0 <3.0.0-0', null],
|
||||
[' 1.x.x+build >2.x.x+build ', '>=1.0.0 <2.0.0-0 >=3.0.0', null],
|
||||
['^1.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['^1.x.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['^1.2.x+build', '>=1.2.0 <2.0.0-0', null],
|
||||
['^1.x+meta-data', '>=1.0.0 <2.0.0-0', null],
|
||||
['^1.x.x+build.123', '>=1.0.0 <2.0.0-0', null],
|
||||
['~1.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['~1.x.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['~1.2.x+build', '>=1.2.0 <1.3.0-0', null],
|
||||
['~1.x+meta-data', '>=1.0.0 <2.0.0-0', null],
|
||||
['~1.x.x+build.123', '>=1.0.0 <2.0.0-0', null],
|
||||
['^1.x.x+build || ~2.x.x+meta', '>=1.0.0 <2.0.0-0||>=2.0.0 <3.0.0-0', null],
|
||||
['~1.x.x+build >2.x+meta', '>=1.0.0 <2.0.0-0 >=3.0.0', null],
|
||||
['^1.x+build.123 <2.x.x+meta-data', '>=1.0.0 <2.0.0-0', null],
|
||||
// // x-ranges with prerelease and build
|
||||
['1.x.x-alpha+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['>1.x.x-alpha+build', '>=2.0.0', null],
|
||||
['>=1.x.x-alpha+build <2.x.x+build', '>=1.0.0 <2.0.0-0', null],
|
||||
['1.x.x-alpha+build || 2.x.x+build', '>=1.0.0 <2.0.0-0||>=2.0.0 <3.0.0-0', null],
|
||||
// long build metadata must be stripped, not bled into the version
|
||||
['4.17.0+' + 'a'.repeat(250) + '3', '4.17.0', { loose: true }],
|
||||
['4.17.0+' + 'a'.repeat(251), '4.17.0', { loose: true }],
|
||||
['v1.0+' + 'a'.repeat(249) + 'x6', '>=1.0.0 <1.1.0-0', null],
|
||||
['1.2.3+' + 'a'.repeat(251) + ' - 2.0.0', '>=1.2.3 <=2.0.0', null],
|
||||
['1.2.3+' + 'a'.repeat(251) + ' - 2.0.0', '>=1.2.3 <=2.0.0', { loose: true }],
|
||||
['> 1.2.3+' + 'a'.repeat(251), '>1.2.3', null],
|
||||
['>= 1.2.3+' + 'a'.repeat(251), '>=1.2.3', { loose: true }],
|
||||
['~1.2.3+' + 'a'.repeat(251), '>=1.2.3 <1.3.0-0', null],
|
||||
['^1.2.3+' + 'a'.repeat(251), '>=1.2.3 <2.0.0-0', null],
|
||||
['1.2.3+sha512.' + 'a'.repeat(251), '1.2.3', { loose: true }],
|
||||
['1.2.3+sha256.' + 'a'.repeat(200) + '.' + 'b'.repeat(200), '1.2.3', { loose: true }],
|
||||
['1.2.3+' + 'a'.repeat(251) + ' || 2.0.0+' + 'b'.repeat(251),
|
||||
'1.2.3||2.0.0', { loose: true }],
|
||||
]
|
||||
Reference in new issue
Block a user