-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.spec.ts
44 lines (34 loc) · 928 Bytes
/
parser.spec.ts
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
import test = require('tape')
import { parse, getPath, setPath } from './parser'
test('parse', function (t) {
t.plan(2)
t.deepEqual(
parse(['(', '+', 'a', 'b', 'c', ')']),
['+', 'a', 'b', 'c'],
'simple expression'
)
t.deepEqual(
parse([
'(', '++', '(', 'aa/sd', 'bs', 'c', ')' ,
'(', 'aasd', 'b&', '+', ')', '(', '(', 'aasd&', '123', ')', 'asdasd', '?asd<', ')', ')',
]),
['++', [ 'aa/sd', 'bs', 'c' ], [ 'aasd', 'b&', '+' ], [ ['aasd&', '123'], 'asdasd', '?asd<' ]],
'complex expression'
)
})
test('getPath', function (t) {
t.plan(1)
t.deepEqual(
getPath([1, 2, 0, 1], ['1', [1, 2, [[1, 2, 3, 4], 2, 3], 4]]),
2,
'get a path from a tree'
)
})
test('setPath', function (t) {
t.plan(1)
t.deepEqual(
setPath(4, [1, 2, 0, 1], ['1', [1, 2, [[1, 2, 3, 4], 2, 3], 4]]),
['1', [1, 2, [[1, 4, 3, 4], 2, 3], 4]],
'set a path in a tree'
)
})