This repository was archived by the owner on Jun 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathparseParentheses-test.js
More file actions
81 lines (62 loc) · 2.59 KB
/
parseParentheses-test.js
File metadata and controls
81 lines (62 loc) · 2.59 KB
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
'use strict'
const assert = require('assert')
const Literally = require('../lib/Language/Helpers/Literally')
const parseParentheses = require('../lib/Language/Helpers/parseParentheses')
describe('ParseParentheses Test', () => {
it('Default', () => {
assert.deepEqual(parseParentheses('foo (bar) baz'), [ 'foo', [ 'bar' ], 'baz' ])
assert.deepEqual(parseParentheses('(foo (bar) baz)'), [ 'foo', [ 'bar' ], 'baz' ])
assert.deepEqual(parseParentheses('foo (bar)'), [ 'foo', [ 'bar'] ])
assert.deepEqual(parseParentheses('(foo)bar'), [ [ 'foo' ], 'bar' ])
assert.deepEqual(parseParentheses('foo (0)'), [ 'foo', [ '0' ] ])
assert.deepEqual(
parseParentheses('foo (bar (nested)) baz'),
[ 'foo', [ 'bar', [ 'nested' ] ], 'baz' ]
)
assert.deepEqual(
parseParentheses('foo boo (bar (nested) something) baz (bar (foo foo))'),
[ 'foo boo', [ 'bar', [ 'nested' ], 'something' ], 'baz', [ 'bar', [ 'foo foo' ] ] ]
)
})
it('Escaping', () => {
assert.deepEqual(
parseParentheses('foo (bar "(bla)") baz'),
[ 'foo', [ 'bar', new Literally('(bla)') ], 'baz' ]
)
assert.deepEqual(
parseParentheses('sample "foo" bar'),
[ 'sample', new Literally('foo'), 'bar' ]
)
assert.deepEqual(
parseParentheses('sample "foo"'),
[ 'sample', new Literally('foo') ]
)
assert.deepEqual(
parseParentheses('bar "(b\\"la)" baz'),
[ 'bar', new Literally('(b\\"la)'), 'baz' ]
)
assert.deepEqual(
parseParentheses('foo "ba\'r" baz'),
[ 'foo', new Literally('ba\'r'), 'baz' ]
)
assert.deepEqual(
parseParentheses('foo (bar \'(b\\\'la)\') baz'),
[ 'foo', [ 'bar', new Literally('(b\\\'la)') ], 'baz']
)
assert.deepEqual(
parseParentheses('bar "b\\\\\" (la) baz'),
[ 'bar', new Literally('b\\\\'), [ 'la' ], 'baz' ]
)
assert.deepEqual(
parseParentheses('"fizz" and "buzz" (with) "bar"'),
[ new Literally('fizz'), 'and', new Literally('buzz'), [ 'with' ], new Literally('bar') ]
)
assert.deepEqual(
parseParentheses('foo \\"boo (bar (nes"ted) s\\"om\\"")ething) baz (bar (foo foo))'),
[ 'foo \\"boo', [ 'bar', [ 'nes', new Literally('ted) s"om"') ], 'ething' ], 'baz', [ 'bar', [ 'foo foo' ] ] ]
)
})
it('Empty', () => {
assert.deepEqual(parseParentheses(''), [])
})
})