From efe6b8f61a726a9157538723793f9a6f2ffd282c Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Sat, 11 Apr 2020 17:16:14 -0500 Subject: [PATCH] Multiple objects in cycle test. See #419. --- test/cycle/byte.t.js | 5 ++--- test/cycle/conditional.t.js | 4 ++-- test/cycle/cycle.js | 23 +++++++++++------------ test/cycle/length-encoded-fixed.t.js | 4 ++-- test/cycle/length-encoded-variable.t.js | 4 ++-- test/cycle/length-encoded-words.t.js | 4 ++-- test/cycle/literal.t.js | 4 ++-- test/cycle/word.t.js | 5 ++--- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/test/cycle/byte.t.js b/test/cycle/byte.t.js index f58ff686..15f0c2a8 100644 --- a/test/cycle/byte.t.js +++ b/test/cycle/byte.t.js @@ -1,12 +1,11 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'byte', define: { object: { word: 8 } }, - object: { word: 0xab }, - buffer: [ 0xab ] + objects: [{ word: 0xab }] }) } diff --git a/test/cycle/conditional.t.js b/test/cycle/conditional.t.js index fe310dd2..df541ff5 100644 --- a/test/cycle/conditional.t.js +++ b/test/cycle/conditional.t.js @@ -1,7 +1,7 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'mysql', define: { object: { @@ -16,7 +16,7 @@ function prove (okay) { ]]]] } }, - object: { value: 250 }, + objects: [{ value: 250 }], stopAt: 'sizeof' }) } diff --git a/test/cycle/cycle.js b/test/cycle/cycle.js index 7483c97c..309741a6 100644 --- a/test/cycle/cycle.js +++ b/test/cycle/cycle.js @@ -18,8 +18,8 @@ const composers = { sizeOf: require('../../sizeof') } -module.exports = function (okay) { - return function (options) { +module.exports = function (okay, options) { + for (const actual of options.objects) { const intermediate = simplified(options.define) const filename = path.resolve(__filename, '../../generated/' + options.name) const packet = { @@ -32,7 +32,7 @@ module.exports = function (okay) { intermediate )(packet.sizeOf) - const sizeOf = packet.sizeOf.object(options.object) + const sizeOf = packet.sizeOf.object(actual) if (options.stopAt == 'sizeof') { console.log('sizeof', sizeOf) @@ -47,7 +47,7 @@ module.exports = function (okay) { const expected = Buffer.alloc(sizeOf) - const serialize = packet.serializers.all.object(options.object) + const serialize = packet.serializers.all.object(actual) const cursor = serialize(expected, 0, expected.length) okay.inc(1) okay(cursor, { @@ -68,8 +68,7 @@ module.exports = function (okay) { okay.inc(1) try { - const object = packet.parsers.all.object(expected, 0) - okay(object, options.object, 'whole parse') + okay(packet.parsers.all.object(expected, 0), actual, 'whole parse') } catch (error) { console.log(packet.parsers.all.object.toString()) throw error @@ -89,7 +88,7 @@ module.exports = function (okay) { try { for (let i = 0; i <= expected.length; i++) { const buffer = Buffer.alloc(sizeOf) - let serialize = packet.serializers.inc.object(options.object), start + let serialize = packet.serializers.inc.object(actual), start { ({ start, serialize } = serialize(buffer, 0, buffer.length - i)) } @@ -120,7 +119,7 @@ module.exports = function (okay) { try { for (let i = 0; i <= expected.length; i++) { - let parse = packet.parsers.inc.object(options.object), start, object + let parse = packet.parsers.inc.object(actual), start, object { ({ start, object, parse } = parse(expected, 0, expected.length - i)) } @@ -130,7 +129,7 @@ module.exports = function (okay) { okay({ start, parse, object }, { start: expected.length, parse: null, - object: options.object + object: actual }, `incremental parse ${i}`) } } catch (error) { @@ -153,7 +152,7 @@ module.exports = function (okay) { try { for (let i = 0; i <= expected.length; i++) { const buffer = Buffer.alloc(sizeOf) - let serialize = packet.serializers.bff.object(options.object), start + let serialize = packet.serializers.bff.object(actual), start { ({ start, serialize } = serialize(buffer, 0, buffer.length - i)) } @@ -185,7 +184,7 @@ module.exports = function (okay) { try { for (let i = 0; i <= expected.length; i++) { - let parse = packet.parsers.bff.object(options.object), start, object + let parse = packet.parsers.bff.object(actual), start, object { ({ start, object, parse } = parse(expected, 0, expected.length - i)) } @@ -195,7 +194,7 @@ module.exports = function (okay) { okay({ start, parse, object }, { start: expected.length, parse: null, - object: options.object + object: actual }, `best-foot-forward parse ${i}`) } } catch (error) { diff --git a/test/cycle/length-encoded-fixed.t.js b/test/cycle/length-encoded-fixed.t.js index cebfea23..1b362edd 100644 --- a/test/cycle/length-encoded-fixed.t.js +++ b/test/cycle/length-encoded-fixed.t.js @@ -1,11 +1,11 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'length-encoded-fixed', define: { object: { array: [ 16, [{ first: 16, second: 16 }] ] } }, - object: { array: [{ first: 0x1234, second: 0x4567 }, { first: 0x89a0, second: 0xcdef }] } + objects: [{ array: [{ first: 0x1234, second: 0x4567 }, { first: 0x89a0, second: 0xcdef }] }] }) } diff --git a/test/cycle/length-encoded-variable.t.js b/test/cycle/length-encoded-variable.t.js index 009dd9d3..1dd6ab5a 100644 --- a/test/cycle/length-encoded-variable.t.js +++ b/test/cycle/length-encoded-variable.t.js @@ -1,11 +1,11 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'length-encoded-variable', define: { object: { array: [ 16, [{ first: [ 16, [ 16 ] ] }] ] } }, - object: { array: [{ first: [ 0x1234, 0x4567 ] }] } + objects: [{ array: [{ first: [ 0x1234, 0x4567 ] }] }] }) } diff --git a/test/cycle/length-encoded-words.t.js b/test/cycle/length-encoded-words.t.js index 21f4282d..95c0fa68 100644 --- a/test/cycle/length-encoded-words.t.js +++ b/test/cycle/length-encoded-words.t.js @@ -1,11 +1,11 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'length-encoded-words', define: { object: { array: [ 16, [ 16 ] ] } }, - object: { array: [ 0x1234, 0x4567, 0x890a, 0xcdef ] } + objects: [{ array: [ 0x1234, 0x4567, 0x890a, 0xcdef ] }] }) } diff --git a/test/cycle/literal.t.js b/test/cycle/literal.t.js index 357e592c..e211820c 100644 --- a/test/cycle/literal.t.js +++ b/test/cycle/literal.t.js @@ -1,13 +1,13 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'literal', define: { object: { padded: [ '0faded', 16, 'facade' ] } }, - object: { padded: 0xabcd } + objects: [{ padded: 0xabcd }] }) } diff --git a/test/cycle/word.t.js b/test/cycle/word.t.js index 70cfb622..0ffb508e 100644 --- a/test/cycle/word.t.js +++ b/test/cycle/word.t.js @@ -1,12 +1,11 @@ require('proof')(0, prove) function prove (okay) { - require('./cycle')(okay)({ + require('./cycle')(okay, { name: 'word', define: { object: { word: 32 } }, - object: { word: 0xabcdef01 }, - buffer: [ 0xab, 0xcd, 0xef, 0x01 ] + objects: [{ word: 0xabcdef01 }] }) }