2017-12-01 09:36:29 +01:00
|
|
|
/* eslint-env mocha */
|
|
|
|
'use strict'
|
|
|
|
|
2020-08-07 15:23:02 +01:00
|
|
|
const uint8ArrayFromString = require('uint8arrays/from-string')
|
2017-12-01 09:36:29 +01:00
|
|
|
const util = require('util')
|
2020-08-07 15:23:02 +01:00
|
|
|
const garbage = [uint8ArrayFromString('00010203040506070809', 'base16'), {}, null, false, undefined, true, 1, 0, uint8ArrayFromString(''), 'aGVsbG93b3JsZA==', 'helloworld', '']
|
2017-12-01 09:36:29 +01:00
|
|
|
|
|
|
|
function doTests (fncName, fnc, num, skipBuffersAndStrings) {
|
|
|
|
if (!num) {
|
|
|
|
num = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
garbage.forEach((garbage) => {
|
2020-08-07 15:23:02 +01:00
|
|
|
if (skipBuffersAndStrings && (garbage instanceof Uint8Array || (typeof garbage) === 'string')) {
|
|
|
|
// skip this garbage because it's a Uint8Array or a String and we were told do do that
|
2017-12-01 09:36:29 +01:00
|
|
|
return
|
|
|
|
}
|
2019-10-24 18:16:41 +02:00
|
|
|
const args = []
|
2017-12-01 09:36:29 +01:00
|
|
|
for (let i = 0; i < num; i++) {
|
|
|
|
args.push(garbage)
|
|
|
|
}
|
2019-07-10 17:15:26 +01:00
|
|
|
it(fncName + '(' + args.map(garbage => util.inspect(garbage)).join(', ') + ')', async () => {
|
|
|
|
try {
|
|
|
|
await fnc.apply(null, args)
|
|
|
|
} catch (err) {
|
|
|
|
return // expected
|
|
|
|
}
|
|
|
|
throw new Error('Expected error to be thrown')
|
2017-12-01 09:36:29 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-22 06:16:02 -04:00
|
|
|
module.exports = { doTests }
|