Skip to content

Commit

Permalink
Multiple objects in cycle test.
Browse files Browse the repository at this point in the history
See #419.
  • Loading branch information
flatheadmill committed Apr 11, 2020
1 parent bc3911d commit efe6b8f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 28 deletions.
5 changes: 2 additions & 3 deletions test/cycle/byte.t.js
Original file line number Diff line number Diff line change
@@ -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 }]
})
}
4 changes: 2 additions & 2 deletions test/cycle/conditional.t.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('proof')(0, prove)

function prove (okay) {
require('./cycle')(okay)({
require('./cycle')(okay, {
name: 'mysql',
define: {
object: {
Expand All @@ -16,7 +16,7 @@ function prove (okay) {
]]]]
}
},
object: { value: 250 },
objects: [{ value: 250 }],
stopAt: 'sizeof'
})
}
23 changes: 11 additions & 12 deletions test/cycle/cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -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, {
Expand All @@ -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
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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) {
Expand All @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/cycle/length-encoded-fixed.t.js
Original file line number Diff line number Diff line change
@@ -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 }] }]
})
}
4 changes: 2 additions & 2 deletions test/cycle/length-encoded-variable.t.js
Original file line number Diff line number Diff line change
@@ -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 ] }] }]
})
}
4 changes: 2 additions & 2 deletions test/cycle/length-encoded-words.t.js
Original file line number Diff line number Diff line change
@@ -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 ] }]
})
}
4 changes: 2 additions & 2 deletions test/cycle/literal.t.js
Original file line number Diff line number Diff line change
@@ -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 }]
})
}
5 changes: 2 additions & 3 deletions test/cycle/word.t.js
Original file line number Diff line number Diff line change
@@ -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 }]
})
}

0 comments on commit efe6b8f

Please sign in to comment.