Skip to content

Commit

Permalink
Fixes/improvements to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed May 17, 2021
1 parent 08ae347 commit ecfb46a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 91 deletions.
16 changes: 12 additions & 4 deletions decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,18 @@ export function setExtractor(extractStrings) {
return function readString(length) {
let string = strings[stringPosition++]
if (string == null) {
strings = extractStrings(position, srcEnd, length, src)
stringPosition = 0
srcStringEnd = 1 // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
string = strings[stringPosition++]
let extraction = extractStrings(position, srcEnd, length, src)
if (typeof extraction == 'string') {
string = extraction
strings = EMPTY_ARRAY
} else {
strings = extraction
stringPosition = 1
srcStringEnd = 1 // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
string = strings[0]
if (string === undefined)
throw new Error('Unexpected end of buffer')
}
}
let srcStringLength = string.length
if (srcStringLength <= length) {
Expand Down
35 changes: 0 additions & 35 deletions index.mjs

This file was deleted.

4 changes: 1 addition & 3 deletions node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { createRequire } from 'module'
const extractor = tryRequire('cbor-extract')
if (extractor)
setExtractor(extractor.extractStrings)
/*
Object.assign(exports, unpackModule.FLOAT32_OPTIONS)
*/

function tryRequire(moduleId) {
try {
let require = createRequire(import.meta.url)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"benchmark": "node ./tests/benchmark.js",
"build": "rollup -c",
"prepare": "npm run build",
"test": "./node_modules/.bin/mocha --experimental-json-modules tests/test.js -u tdd"
"test": "./node_modules/.bin/mocha --experimental-json-modules tests/test**.*js -u tdd"
},
"type": "module",
"main": "./dist/node.cjs",
Expand Down
18 changes: 6 additions & 12 deletions tests/test-compatibility.js → tests/test-compatibility.cjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import * as data from './example4.json';
import * as msgpackr from '..'
import * as chai from 'chai'
const data = require('./example4.json');
const cborX = require('..');
const chai = require('chai');

/*function tryRequire(module) {
function tryRequire(module) {
try {
return require(module)
} catch(error) {
}
}
//if (typeof chai === 'undefined') { chai = require('chai') }
assert = chai.assert
if (typeof cborX === 'undefined') { cborX = require('..') }
const assert = chai.assert
var cbor_module = tryRequire('cbor');
var decode = cborX.decode
var encode = cborX.encode
//if (typeof msgpackr === 'undefined') { msgpackr = require('..') }
var msgpack_msgpack = tryRequire('@msgpack/msgpack');
var msgpack_lite = tryRequire('msgpack-lite');*/
var unpack = msgpackr.unpack
var pack = msgpackr.pack

addCompatibilitySuite = (data) => () => {
const addCompatibilitySuite = (data) => () => {
if (cbor_module) {
test('from cbor', function(){
var serialized = cbor_module.encode(data)
Expand Down
12 changes: 7 additions & 5 deletions tests/test-node-stream.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PackrStream, UnpackrStream } from '../node.js'
import { EncoderStream, DecoderStream } from '../node.js'
import stream from 'stream'
import chai from 'chai'
var assert = chai.assert

suite('msgpackr node stream tests', function(){
suite('cbor-x node stream tests', function(){
test('serialize/parse stream', () => {
const serializeStream = new PackrStream({
const serializeStream = new EncoderStream({
})
const parseStream = new UnpackrStream()
const parseStream = new DecoderStream()
serializeStream.pipe(parseStream)
const received = []
parseStream.on('data', data => {
Expand All @@ -31,7 +33,7 @@ suite('msgpackr node stream tests', function(){
})
})
test('stream from buffer', () => new Promise(async resolve => {
const parseStream = new UnpackrStream()
const parseStream = new DecoderStream()
let values = []
parseStream.on('data', (value) => {
values.push(value)
Expand Down
31 changes: 0 additions & 31 deletions tests/test.mjs

This file was deleted.

0 comments on commit ecfb46a

Please sign in to comment.