-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathexpression.spec.ts
52 lines (51 loc) · 2.02 KB
/
expression.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
45
46
47
48
49
50
51
52
import { Slim } from '../dist/index';
import { parse } from '../src/expression';
import assert from 'assert';
describe('expression', () => {
describe('parse', () => {
it('should find multiple property accessors', () => {
const result = parse(`this.something + 4 + this.somethingElse`).paths;
assert.strictEqual(result.length, 2);
assert.strictEqual(result[0], 'something');
assert.strictEqual(result[1], 'somethingElse');
});
it('should find one property accessor', () => {
const result = parse(`this.name`).paths;
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0], 'name');
});
it('should find one property accessor with wrapping expressions', () => {
const result = parse(`42 + this.name`).paths;
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0], 'name');
});
it('should find method call', () => {
const result = parse(`this.fn(4)`).paths;
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0], 'fn');
});
it('should find method call with argument', () => {
const result = parse(`this.fn(this.prop)`).paths;
assert.strictEqual(result.length, 2);
assert.strictEqual(result[0], 'fn');
assert.strictEqual(result[1], 'prop');
});
it('should find nested function calls', () => {
const result = parse(`this.fn(this.fn2(this.someProp + 50))`).paths;
assert.strictEqual(result.length, 3);
assert.strictEqual(result[0], 'fn');
assert.strictEqual(result[1], 'fn2');
assert.strictEqual(result[2], 'someProp');
});
it('should find nested calls with multiple accessors', () => {
const result = parse(
`this.say(this.myName + ' i am from ', this.getCity(this.address))`
).paths;
assert.strictEqual(result.length, 4);
assert.strictEqual(result[0], 'say');
assert.strictEqual(result[1], 'myName');
assert.strictEqual(result[2], 'getCity');
assert.strictEqual(result[3], 'address');
});
});
});