-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.js
67 lines (54 loc) · 1.92 KB
/
parser.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
var assert = require('assert')
var bracery = require('../index')
var initJson = { abc: 'def',
hello: '[hello|hi]',
world: ['world', 'planet'],
test1: 'testing',
test2: '~TEST1',
test3: 'x~test3',
test4: '"e{~TEST1}' }
var b = new bracery.Bracery (initJson)
describe('validation', function() {
validate ('~x')
validate ('"e{~x}')
validate ('"e{~x }')
validate ('"e~x', '"e{~x}')
validate ('"e&cap~x', '"e~X')
validate ('&rep{~x}{3}')
validate ('&rep{~x}{03}', '&rep{~x}{3}')
validate ('&rep{~x}{3,5}')
validate ('&eq$x$y')
validate ('&eq{$x}$y', '&eq$x$y')
validate ('&eq$x{$y}', '&eq$x$y')
validate ('&eq{$x}{$y}', '&eq$x$y')
validate ('&eq$x{abc}')
validate ('&eq{$x}{abc}', '&eq$x{abc}')
validate ('&eq{abc}$y')
validate ('&eq{abc}{$y}', '&eq{abc}$y')
validate ('&eq{~abc}{~{abc}def}')
validate ('$y=&eq&eq$b{abc}&eq{t}$x', '$y={&eq&eq$b{abc}&eq{t}$x}')
validate ('&set$y{xyz}', '$y={xyz}')
validate ('&set{$y}{xyz}', '$y={xyz}')
validate ('&set{y}{xyz}', '$y={xyz}')
validate ('&reduce$n:$x$r={zero dogs}&add$r$n')
validate ('&reduce$n{$x}$r{zero dogs}{&add{$r}{$n}}', '&reduce$n:$x$r={zero dogs}&add$r$n')
validate ('&map$n:$x{$n,}')
validate ('&map$n{$x}{$n,}', '&map$n:$x{$n,}')
validate ('[a=>b|c]', '$a={"e[b|c]}')
validate ('[a\\=>b|c]', '[a\\=>b|c]')
validate ('[c|a\\=>b]', '[c|a=>b]')
validate ('[a:b|c]', '[a\\:b|c]')
validate ('[a:b\\|c]', '$a={b\\|c}')
validate ('$x=hello', '$x={hello}')
validate ('$x=hello kid', '$x={hello}kid')
validate ('"e{$a=1 $a==3}', '"e{$a={1}$a==3}')
})
function validate (lhs, norm, config) {
var expected = norm || lhs
it('should parse ' + lhs + (norm ? (' as ' + norm) : ''),
function (done) {
var result = b.normalize (lhs)
assert.equal (result, expected)
done()
})
}