Skip to content

Commit 10f2725

Browse files
sehropebendrucker
authored andcommitted
test: Convert binary test vectors via Buffer.from(...) (#89)
Convert non-Buffer binary test vectors via Buffer.from(...) to ensure that all binary tests are executed on a Buffer object. Previously some tests would pass objects that could be accessed as array like objects such as strings or arrays.
1 parent 0ac98fa commit 10f2725

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ test('types', function (t) {
1010
var parser = getTypeParser(type.id, type.format)
1111
type.tests.forEach(function (tests) {
1212
var input = tests[0]
13+
if (type.format === 'binary' && input !== null && !Buffer.isBuffer(input)) {
14+
if (Array.isArray(input) || typeof(input) === 'string') {
15+
input = Buffer.from(input)
16+
} else {
17+
throw new Error('Binary test inputs must be null, a String, a Buffer, or an Array')
18+
}
19+
}
1320
var expected = tests[1]
1421
var result = parser(input)
1522
if (typeof expected === 'function') {

0 commit comments

Comments
 (0)