-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add a test to make sure we search using a boolean AND operation
- Loading branch information
1 parent
6b67456
commit 2e86556
Showing
2 changed files
with
45 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,53 @@ | ||
var assert = require('assert') | ||
var search = require('./') | ||
const assert = require('assert') | ||
const search = require('./') | ||
|
||
// Returns matches | ||
var get = search(['foo', 'bar', 'foobar']) | ||
var res = get('foo') | ||
const get = search(['foo', 'bar', 'foobar']) | ||
const res = get('foo') | ||
assert.strictEqual(res[0], 'foo') | ||
assert.strictEqual(res[1], 'foobar') | ||
assert.strictEqual(res.length, 2) | ||
|
||
// Matches whole object and returns same object instances | ||
var arr2 = [{ id: 1, name: 'Test' }, { id: 2, name: 'Marc' }] | ||
var get2 = search(arr2) | ||
var res2 = get2('test') | ||
const arr2 = [{ id: 1, name: 'Test' }, { id: 2, name: 'Marc' }] | ||
const get2 = search(arr2) | ||
const res2a = get2('test') | ||
|
||
assert.strictEqual(res2[0], arr2[0]) | ||
assert.strictEqual(res2.length, 1) | ||
assert.strictEqual(res2a[0], arr2[0]) | ||
assert.strictEqual(res2a.length, 1) | ||
|
||
res2 = get2(1) | ||
assert.strictEqual(res2[0], arr2[0]) | ||
assert.strictEqual(res2.length, 1) | ||
const res2b = get2(1) | ||
assert.strictEqual(res2b[0], arr2[0]) | ||
assert.strictEqual(res2b.length, 1) | ||
|
||
res2 = get2(2) | ||
assert.strictEqual(res2[0], arr2[1]) | ||
assert.strictEqual(res2.length, 1) | ||
const res2c = get2(2) | ||
assert.strictEqual(res2c[0], arr2[1]) | ||
assert.strictEqual(res2c.length, 1) | ||
|
||
// Allows to restrict search one property | ||
var arr3 = [{ id: 1, name: 'Test' }, { id: 2, name: 'Marc' }] | ||
var get3 = search(arr3, 'name') | ||
var res3 = get3('Marc') | ||
assert.strictEqual(res3[0], arr3[1]) | ||
assert.strictEqual(res3.length, 1) | ||
const arr3 = [{ id: 1, name: 'Test' }, { id: 2, name: 'Marc' }] | ||
const get3 = search(arr3, 'name') | ||
const res3a = get3('Marc') | ||
assert.strictEqual(res3a[0], arr3[1]) | ||
assert.strictEqual(res3a.length, 1) | ||
|
||
res3 = get3(2) | ||
assert.strictEqual(res3.length, 0) | ||
const res3b = get3(2) | ||
assert.strictEqual(res3b.length, 0) | ||
|
||
// Search using umlauts is supported | ||
var arr4 = [{ id: 1, name: 'Zürich' }, { id: 2, name: 'Reykjavík' }] | ||
var get4 = search(arr4, 'name') | ||
var res4 = get4('zurich') | ||
assert.strictEqual(res4[0], arr4[0]) | ||
assert.strictEqual(res4.length, 1) | ||
|
||
res4 = get4('reykjavik') | ||
assert.strictEqual(res4[0], arr4[1]) | ||
assert.strictEqual(res4.length, 1) | ||
const arr4 = [{ id: 1, name: 'Zürich' }, { id: 2, name: 'Reykjavík' }] | ||
const get4 = search(arr4, 'name') | ||
const res4a = get4('zurich') | ||
assert.strictEqual(res4a[0], arr4[0]) | ||
assert.strictEqual(res4a.length, 1) | ||
|
||
const res4b = get4('reykjavik') | ||
assert.strictEqual(res4b[0], arr4[1]) | ||
assert.strictEqual(res4b.length, 1) | ||
|
||
const res4c = get4('zu rich') | ||
assert.strictEqual(res4c[0], arr4[0]) | ||
assert.strictEqual(res4c.length, 1) | ||
|
||
const res4d = get4('zu reyk') | ||
assert.strictEqual(res4d.length, 0) |