-
Notifications
You must be signed in to change notification settings - Fork 2
/
data.js
83 lines (75 loc) · 3.09 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const assert = require('assert'),
sh = require('../dist/index.js'),
countries = require('./data/countries.json'),
licences = require('./data/licenses.json'),
laureate = require('./data/laureate.json'),
big = require('./data/big.json'),
theme = require('./data/theme.json');
describe('Search starts', () => {
describe('Countrynames search', () => {
it('should find 3 elements containing `az`', () => {
const search = sh.forValue(countries, /az/);
assert.strictEqual(3, search.length);
});
it('should find 27 elements containing `al`', () => {
const search = sh.forValue(countries, /al/);
assert.strictEqual(27, search.length);
});
});
describe('Licences search', () => {
it('should find 4 elements containing `MIT`', () => {
const search = sh.forValue(licences, 'MIT');
assert.strictEqual(4, search.length);
});
it('should find 1 elements name:MIT', () => {
const search = sh.forKeyValue(licences, {key:"name", value:"MIT"});
assert.strictEqual(1, search.length);
});
});
describe('Laureate search', () => {
const search = sh.forValue(laureate, 'Albert');
it('should find 6 elements with value `Albert`', () => {
assert.strictEqual(6, search.length);
});
it('one of those has to be `Einstein`', () => {
const Einstein = sh.forValue(search, 'Einstein');
assert.strictEqual(1, Einstein.length);
});
});
describe('Search in a big file', () => {
it('should find 181 companies with a double `l` on the name', () => {
const search = sh.forKeyValue(big, { key: "company", value: /LL/ })
assert.strictEqual(181, search.length);
});
it('should find 3245 companies with an `A` on the name', () => {
const search = sh.forKeyValue(big, { key: "company", value: /A/ })
assert.strictEqual(3245, search.length);
});
it('should find 2109 companies with an `A` in the address', () => {
const search = sh.forKeyValue(big, { key: "address", value: /A/ })
assert.strictEqual(2109, search.length);
});
it('should find 6137 companies with an `A` in the address, caseinsensitive', () => {
const search = sh.forKeyValue(big, { key: "address", value: /A/i })
assert.strictEqual(6137, search.length);
});
});
describe('Search in a deep file using less trivial regexp', () => {
it('should find 13 elements hex3', () => {
const search = sh.forValue(theme, /^#[0-9a-z]{3}$/i);
assert.strictEqual(13, search.length);
});
it('should find 4 elements hex6', () => {
const search = sh.forValue(theme, /^#[0-9a-z]{6}$/i);
assert.strictEqual(4, search.length);
});
it('should find 10 elements rgb', () => {
const search = sh.forValue(theme, /^rgb\(/);
assert.strictEqual(10, search.length);
});
it('should find 12 elements rgba', () => {
const search = sh.forValue(theme, /^rgba\(/);
assert.strictEqual(12, search.length);
});
});
});