-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathparse.test.js
71 lines (66 loc) · 1.4 KB
/
parse.test.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
/* eslint-disable no-undef */
import parse from './parse';
// When Input is Empty
test('empty pseudocode', () => {
expect(parse('')).toEqual({});
});
// Test signle basic parse
test('single basic procedure', () => {
expect(parse(`
\\Code{
Main
\\In{
while t not Empty
\\In}
\\Code}
`)).toEqual(
{
Main: [{
code: '\xa0\xa0\xa0\xa0while t not Empty', explanation: '', indentation: 1,
}],
},
);
});
// Test whether explanation function can work well
test('procedure with explanation', () => {
expect(parse(`
\\Code{
Main
\\In{
while t not Empty
\\Expl{ We have found a node with the desired key k.
\\Expl}
\\In}
\\Code}
`)).toEqual(
{
Main: [{
code: '\xa0\xa0\xa0\xa0while t not Empty', explanation: ' We have found a node with the desired key k.', indentation: 1,
}],
},
);
});
// Test whether Ref function can work well.
test('procedure with ref', () => {
expect(parse(`
\\Code{
Main
\\In{
Ref thing \\Ref Insert
\\In}
\\Code}
\\Code{
Insert
\\In{
something
\\In}
\\Code}
`)).toEqual({
Insert: [{
code: '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0something', explanation: '', indentation: 1,
}],
Main: [{
code: '\xa0\xa0\xa0\xa0Ref thing', explanation: '', indentation: 1, ref: 'Insert',
}],
});
});