From 39fba2e7f094afa24c687139205609c355892857 Mon Sep 17 00:00:00 2001 From: Moos Date: Sun, 14 Oct 2018 22:50:12 -0700 Subject: [PATCH] fix tests --- src/common.js | 2 -- src/node/dataFile.js | 6 ++---- src/wordpos.js | 16 ++++++++++++++++ test/wordpos_test.js | 6 +++--- 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/wordpos.js diff --git a/src/common.js b/src/common.js index 8ca9a65..b03fd8b 100644 --- a/src/common.js +++ b/src/common.js @@ -172,8 +172,6 @@ function is(pos){ * Credit for this routine to https://github.com/NaturalNode/natural */ function lineDataToJSON(line, location) { - // if (!dataCheck(line, location)) return new Error('Bad data at location ' + location); - var data = line.split('| '), tokens = data[0].split(/\s+/), ptrs = [], diff --git a/src/node/dataFile.js b/src/node/dataFile.js index df3d863..688df13 100644 --- a/src/node/dataFile.js +++ b/src/node/dataFile.js @@ -52,11 +52,9 @@ function readLocation(location, callback) { return; } //console.log(' read %d bytes at <%d>', count, location); + if (!dataCheck(str, location)) return callback(new Error('Bad data at location ' + location)); - callback(null, function() { - if (!dataCheck(str, location)) return new Error('Bad data at location ' + location); - lineDataToJSON(str, location) - }); + callback(null, lineDataToJSON(str, location)); }); function readChunk(pos, cb) { diff --git a/src/wordpos.js b/src/wordpos.js new file mode 100644 index 0000000..e1a974e --- /dev/null +++ b/src/wordpos.js @@ -0,0 +1,16 @@ +/*! +* wordpos.js +* +* Node.js part-of-speech utilities using WordNet database. +* +* Copyright (c) 2012-2019 mooster@42at.com +* https://github.com/moos/wordpos +* +* Released under MIT license +*/ + +if (process.browser) { + module.exports = require('./browser'); +} else { + module.exports = require('./node'); +} diff --git a/test/wordpos_test.js b/test/wordpos_test.js index 79b6a2b..aff5849 100644 --- a/test/wordpos_test.js +++ b/test/wordpos_test.js @@ -372,7 +372,7 @@ describe('seek()...', function() { it('should handle bad offset', function(done) { wordpos.seek('foobar', 'a', function(err, result){ assert(err instanceof Error); - assert.equal(err.message, 'offset must be valid positive number.'); + assert.equal(err.message, 'Offset must be valid positive number: foobar'); done(); }).catch(_.noop); // UnhandledPromiseRejectionWarning }); @@ -498,8 +498,8 @@ describe('Promise pattern', function() { it('seek() - bad offset', function () { return wordpos.seek('foobar', 'a').catch(function (err) { assert(err instanceof Error); - assert.equal(err.message, 'offset must be valid positive number.'); + assert.equal(err.message, 'Offset must be valid positive number: foobar'); }); }); -}); \ No newline at end of file +});