-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathtest315.js
147 lines (126 loc) · 3.77 KB
/
test315.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
} else {
__dirname = '.';
}
describe('Test 315a Brackets for SEARCH', function () {
var data = {a: 10, b: 100, c: {d: 5, e: 6}};
it('1. Simple Brackets', function (done) {
var res = alasql('SEARCH a FROM ?', [data]);
assert(res[0] == 10);
done();
});
it('2. Simple Brackets', function (done) {
var res = alasql('SEARCH (a) FROM ?', [data]);
assert(res[0] == 10);
done();
});
it('3. Simple Brackets', function (done) {
var res = alasql('SEARCH WITH(c d) FROM ?', [data]);
assert(res[0] == 5);
done();
});
it('4. Simple Brackets', function (done) {
var res = alasql('SEARCH c WITH(d) FROM ?', [data]);
assert(res[0] == 5);
done();
});
it('5. Simple Brackets', function (done) {
var res = alasql('SEARCH WITH(c) d FROM ?', [data]);
// console.log(43,res);
assert(res[0] == 5);
done();
});
it('6. Simple Brackets', function (done) {
var res = alasql('SEARCH with(c) with(d) FROM ?', [data]);
// console.log(51,res);
assert(res[0] == 5);
done();
});
});
describe('Test 315b Brackets for SEARCH', function () {
var data = [{a: 1}, {b: {a: 2}, c: 2}, {c: 3}];
it('1. Simple Brackets', function (done) {
var res = alasql('SEARCH / / a FROM ?', [data]);
assert(res == 2);
done();
});
it('2. Simple Brackets', function (done) {
var res = alasql('SEARCH / a FROM ?', [data]);
assert.deepEqual(res, [1]);
done();
});
it('3. Simple Brackets', function (done) {
var res = alasql('SEARCH / + a FROM ?', [data]);
// console.log(res);
assert.deepEqual(res, [1, 2]);
done();
});
it('4. Simple Brackets', function (done) {
var res = alasql('SEARCH (/)+ a FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
done();
});
it('5. Simple Brackets', function (done) {
var res = alasql('SEARCH ((/)+ (a)) FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
done();
});
it('6. Simple Brackets', function (done) {
var res = alasql('SEARCH (/)? a FROM ?', [data]);
assert.deepEqual(res, [1]);
// console.log(res);
done();
});
});
describe('Test 315c Brackets for SEARCH', function () {
var data = [{a: 1}, {b: {a: 2}, c: 2}, {c: 3}];
it('1. Simple Brackets', function (done) {
var res = alasql('SEARCH /+ a FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
done();
});
it('2. Simple Brackets', function (done) {
var data = [{a: 1}, {b: {a: 2}, c: 2}, {c: 3}];
var res = alasql('SEARCH / + a FROM ?', [data]);
// console.log(res);
done();
});
it('3. Simple Brackets', function (done) {
var res = alasql('SEARCH / + FROM ?', [data]);
assert.deepEqual(res, [{a: 1}, {b: {a: 2}, c: 2}, {c: 3}, 1, {a: 2}, 2, 3, 2]);
done();
});
it('4. Simple Brackets', function (done) {
var res = alasql('SEARCH ((/+) a) FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
var res = alasql('SEARCH ALL((/+) a) ORDER BY(DESC) FROM ?', [data]);
assert.deepEqual(res, [2, 1]);
var res = alasql('SEARCH ALL((/+) a) ORDER BY() FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
var res = alasql('SEARCH ALL((/+) a) ORDER BY(ASC) FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
done();
});
it('5. Simple Brackets', function (done) {
var res = alasql('SEARCH ALL((/+) a) ORDER BY() FROM ?', [data]);
assert.deepEqual(res, [1, 2]);
done();
});
it('6. Simple Brackets', function (done) {
var res = alasql('SEARCH ALL((/+) a) ORDER BY(DESC) FROM ?', [data]);
assert.deepEqual(res, [2, 1]);
done();
});
it('7. Simple Brackets', function (done) {
var res = alasql('SEARCH ALL(/+a) ORDER BY(DESC) FROM ?', [data]);
assert.deepEqual(res, [2, 1]);
done();
});
it('8. Simple Brackets', function (done) {
var res = alasql('SEARCH ALL(/ *a) ORDER BY(DESC) FROM ?', [data]);
assert.deepEqual(res, [2, 1]);
done();
});
});