lucene-filter.js

Data filter for lucene queries
git clone git://git.finwo.net/lib/lucene-filter.js
Log | Files | Refs | README | LICENSE

commit 844d03a39bf1705160bf0e686a88a20cf70b678d
parent d37dbfe8c491a38db3ecfadf03c36e99bba4ff09
Author: finwo <finwo@pm.me>
Date:   Tue, 21 Apr 2020 13:14:44 +0200

Changed tests from jest to tape

Diffstat:
Mscripts/build.sh | 1-
Msrc/field.test.js | 14++++++++------
Msrc/implicit.test.js | 28+++++++++++++++-------------
Msrc/operators/and-not.test.js | 51++++++++++++++++++++++++++++-----------------------
Msrc/operators/and.test.js | 51++++++++++++++++++++++++++++-----------------------
Msrc/operators/or-not.test.js | 51++++++++++++++++++++++++++++-----------------------
Msrc/operators/or.test.js | 51++++++++++++++++++++++++++++-----------------------
7 files changed, 135 insertions(+), 112 deletions(-)

diff --git a/scripts/build.sh b/scripts/build.sh @@ -5,7 +5,6 @@ [ -z ${APPROOT+x} ] && export APPROOT=$(dirname $SCRIPTS) PATH="${APPROOT}/node_modules/.bin:${PATH}" -# BROWSERIFY="browserify -p esmify" BROWSERIFY="browserify" UGLIFY="${APPROOT}/node_modules/uglify-es/bin/uglifyjs" diff --git a/src/field.test.js b/src/field.test.js @@ -10,10 +10,12 @@ tape('Ensure basics', async t => { t.equal(typeof field, 'function', 'Field is an exported function'); }); -// tape('Function passthrough', async t => { -// expect(field('foo',{foo:'bar'},pass)).toBe('bar'); -// }); +tape('Function passthrough', async t => { + t.plan(1); + t.equal(field('foo',{foo:'bar'},pass), 'bar', 'Fetch field by name works'); +}); -// tape('Pass to explicit', async t => { -// expect(field('<implicit>',{foo:'bar'},pass)).toBe('bar'); -// }); +tape('Pass to explicit', async t => { + t.plan(1); + t.equal(field('<implicit>',{foo:'bar'},pass), 'bar', 'Implicit fetch works'); +}); diff --git a/src/implicit.test.js b/src/implicit.test.js @@ -1,16 +1,18 @@ -// import expect from 'expect'; -// const implicit = require('./implicit'); +import tape from 'tape'; +import implicit from './implicit'; -// test('Ensure basics', async () => { -// expect(typeof implicit).toBe('function'); -// }); +tape('Ensure basics', async t => { + t.plan(1); + t.equal(typeof implicit, 'function', 'Implicit exports a function'); +}); -// test('Verify loop', async () => { -// let out = []; -// implicit({foo:'bar',pizza:'calzone'}, arg => { -// out.push(arg); -// }); +tape('Verify loop', async t => { + let out = []; + implicit({foo:'bar',pizza:'calzone'}, arg => { + out.push(arg); + }); -// expect(out[0]).toBe('bar'); -// expect(out[1]).toBe('calzone'); -// }); + t.plan(2); + t.equal(out[0], 'bar' , 'First output is "bar"'); + t.equal(out[1], 'calzone', 'Second output is "calzone"'); +}); diff --git a/src/operators/and-not.test.js b/src/operators/and-not.test.js @@ -1,27 +1,32 @@ -// import expect from 'expect'; -// const andNot = require('./index')['AND NOT']; +import tape from 'tape'; +import operators from './index'; -// const minus = n => () => -n(), -// zero = () => 0, -// one = () => 1, -// two = () => 2, -// three = () => 3, -// four = () => 4, -// five = () => 5; +const andNot = operators['AND NOT']; -// test('Verifying positive numbers', async () => { -// expect(andNot(zero , one )()).toBe(0); -// expect(andNot(one , two )()).toBe(1); -// expect(andNot(two , three)()).toBe(2); -// expect(andNot(three, four )()).toBe(3); -// expect(andNot(four , five )()).toBe(4); -// }); +const minus = n => () => -n(), + zero = () => 0, + one = () => 1, + two = () => 2, + three = () => 3, + four = () => 4, + five = () => 5; -// test('Mixing negative numbers', async () => { -// expect(andNot(minus(two), one )()).toBe(-1); -// expect(andNot( two , minus(one))()).toBe( 1); -// }); +tape('Verifying positive numbers', async t => { + t.plan(5); + t.equal(andNot(zero , one )(), 0, '0 &! 1 == 0'); + t.equal(andNot(one , two )(), 1, '1 &! 2 == 1'); + t.equal(andNot(two , three)(), 2, '2 &! 3 == 2'); + t.equal(andNot(three, four )(), 3, '3 &! 4 == 3'); + t.equal(andNot(four , five )(), 4, '4 &! 5 == 4'); +}); -// test('Matching abs', async () => { -// expect(andNot(minus(two), two)()).toBe(-2); -// }); +tape('Mixing negative numbers', async t => { + t.plan(2); + t.equal(andNot(minus(two), one )(), -1, '-2 &! 1 == -1'); + t.equal(andNot( two , minus(one))(), 1, ' 2 &! -1 == 1'); +}); + +tape('Matching abs', async t => { + t.plan(1); + t.equal(andNot(minus(two), two)(), -2, '-2 &! 2 == -2'); +}); diff --git a/src/operators/and.test.js b/src/operators/and.test.js @@ -1,27 +1,32 @@ -// import expect from 'expect'; -// const and = require('./index')['AND']; +import tape from 'tape'; +import operators from './index'; -// const minus = n => () => -n(), -// zero = () => 0, -// one = () => 1, -// two = () => 2, -// three = () => 3, -// four = () => 4, -// five = () => 5; +const and = operators['AND']; -// test('Verifying positive numbers', async () => { -// expect(and(zero , one )()).toBe(0); -// expect(and(one , two )()).toBe(1); -// expect(and(two , three)()).toBe(2); -// expect(and(three, four )()).toBe(3); -// expect(and(four , five )()).toBe(4); -// }); +const minus = n => () => -n(), + zero = () => 0, + one = () => 1, + two = () => 2, + three = () => 3, + four = () => 4, + five = () => 5; -// test('Mixing negative numbers', async () => { -// expect(and(minus(two), one )()).toBe( 1); -// expect(and( two , minus(one))()).toBe(-1); -// }); +tape('Verifying positive numbers', async t => { + t.plan(5); + t.equal(and(zero , one )(), 0, '0 && 1 == 0'); + t.equal(and(one , two )(), 1, '1 && 2 == 1'); + t.equal(and(two , three)(), 2, '2 && 3 == 2'); + t.equal(and(three, four )(), 3, '3 && 4 == 3'); + t.equal(and(four , five )(), 4, '4 && 5 == 4'); +}); -// test('Matching abs', async () => { -// expect(and(minus(two), two)()).toBe(-2); -// }); +tape('Mixing negative numbers', async t => { + t.plan(2); + t.equal(and(minus(two), one )(), 1, '-2 && 1 == 1'); + t.equal(and( two , minus(one))(), -1, ' 2 && -1 == -1'); +}); + +tape('Matching abs', async t => { + t.plan(1); + t.equal(and(minus(two), two)(), -2, '-2 && 2 == -2'); +}); diff --git a/src/operators/or-not.test.js b/src/operators/or-not.test.js @@ -1,27 +1,32 @@ -// import expect from 'expect'; -// const orNot = require('./index')['OR NOT']; +import tape from 'tape'; +import operators from './index'; -// const minus = n => () => -n(), -// zero = () => 0, -// one = () => 1, -// two = () => 2, -// three = () => 3, -// four = () => 4, -// five = () => 5; +const orNot = operators['OR NOT']; -// test('Verifying positive numbers', async () => { -// expect(orNot(zero , one )()).toBe(-1); -// expect(orNot(one , two )()).toBe(-2); -// expect(orNot(two , three)()).toBe(-3); -// expect(orNot(three, four )()).toBe(-4); -// expect(orNot(four , five )()).toBe(-5); -// }); +const minus = n => () => -n(), + zero = () => 0, + one = () => 1, + two = () => 2, + three = () => 3, + four = () => 4, + five = () => 5; -// test('Mixing negative numbers', async () => { -// expect(orNot(minus(two), one )()).toBe(-2); -// expect(orNot( two , minus(one))()).toBe( 2); -// }); +tape('Verifying positive numbers', async t => { + t.plan(5); + t.equal(orNot(zero , one )(), -1, '0 |! 1 == -1'); + t.equal(orNot(one , two )(), -2, '1 |! 2 == -2'); + t.equal(orNot(two , three)(), -3, '2 |! 3 == -3'); + t.equal(orNot(three, four )(), -4, '3 |! 4 == -4'); + t.equal(orNot(four , five )(), -5, '4 |! 5 == -5'); +}); -// test('Matching abs', async () => { -// expect(orNot(minus(two), two)()).toBe(-2); -// }); +tape('Mixing negative numbers', async t => { + t.plan(2); + t.equal(orNot(minus(two), one )(), -2, '-2 |! -1 = -2'); + t.equal(orNot( two , minus(one))(), 2, ' 2 |! -1 = 2'); +}); + +tape('Matching abs', async t => { + t.plan(1); + t.equal(orNot(minus(two), two)(), -2, '-2 |! 2 == -2'); +}); diff --git a/src/operators/or.test.js b/src/operators/or.test.js @@ -1,27 +1,32 @@ -// import expect from 'expect'; -// const or = require('./index')['OR']; +import tape from 'tape'; +import operators from './index'; -// const minus = n => () => -n(), -// zero = () => 0, -// one = () => 1, -// two = () => 2, -// three = () => 3, -// four = () => 4, -// five = () => 5; +const or = operators['OR']; -// test('Verifying positive numbers', async () => { -// expect(or(zero , one )()).toBe(1); -// expect(or(one , two )()).toBe(2); -// expect(or(two , three)()).toBe(3); -// expect(or(three, four )()).toBe(4); -// expect(or(four , five )()).toBe(5); -// }); +const minus = n => () => -n(), + zero = () => 0, + one = () => 1, + two = () => 2, + three = () => 3, + four = () => 4, + five = () => 5; -// test('Mixing negative numbers', async () => { -// expect(or(minus(two), one )()).toBe(-2); -// expect(or( two , minus(one))()).toBe( 2); -// }); +tape('Verifying positive numbers', async t => { + t.plan(5); + t.equal(or(zero , one )(), 1, '0 || 1 == 1'); + t.equal(or(one , two )(), 2, '1 || 2 == 2'); + t.equal(or(two , three)(), 3, '2 || 3 == 3'); + t.equal(or(three, four )(), 4, '3 || 4 == 4'); + t.equal(or(four , five )(), 5, '4 || 5 == 5'); +}); -// test('Matching abs', async () => { -// expect(or(minus(two), two)()).toBe(2); -// }); +tape('Mixing negative numbers', async t => { + t.plan(2); + t.equal(or(minus(two), one )(), -2, '-2 || 1 == -2'); + t.equal(or( two , minus(one))(), 2, ' 2 || -1 == 2'); +}); + +tape('Matching abs', async t => { + t.plan(1); + t.equal(or(minus(two), two)(), 2, '-2 || 2 == 2'); +});