Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions test/classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,42 @@ test('range tests', t => {
})

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()
}))
const assertions = rangeParse.reduce((count, [, expect]) =>
count + (expect === null ? 1 : 2), 0)
t.plan(assertions)
rangeParse.forEach(([range, expect, options]) => {
const description = `${range} ${JSON.stringify(options)}`
if (expect === null) {
t.throws(() => new Range(range, options), TypeError, `invalid range: ${description}`)
} else {
const parsed = new Range(range, options)
t.equal(parsed.range || '*', expect, `${description} => ${expect}`)
t.equal(parsed.range,
new Range(expect, { includePrerelease: parsed.includePrerelease }).range,
`parsing both yields same result: ${description}`)
}
})
})

test('range parsing covers every option combination', t => {
const inputsByOptions = new Map()
for (const [range, , options] of rangeParse) {
const loose = !!(options && options.loose)
const includePrerelease = !!(options && options.includePrerelease)
const key = `${loose}:${includePrerelease}`
if (!inputsByOptions.has(key)) {
inputsByOptions.set(key, [])
}
inputsByOptions.get(key).push(range)
}

const combinations = ['false:false', 'true:false', 'false:true', 'true:true']
t.strictSame([...inputsByOptions.keys()], combinations, 'all four modes are present')
const defaultInputs = inputsByOptions.get('false:false')
for (const key of combinations.slice(1)) {
t.strictSame(inputsByOptions.get(key), defaultInputs, `${key} covers the same inputs`)
}
t.end()
})

test('throw for empty comparator set, even in loose mode', t => {
Expand Down
Loading
Loading