-
Notifications
You must be signed in to change notification settings - Fork 1
/
generatorTest.js
80 lines (75 loc) · 2.88 KB
/
generatorTest.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
72
73
74
75
76
77
78
79
80
/*
* PHP-To-AST - PHP parser
* Copyright (c) Dan Phillimore (asmblah)
* http://uniter.github.com/phptoast/
*
* Released under the MIT license
* https://github.com/uniter/phptoast/raw/master/MIT-LICENSE.txt
*/
'use strict';
var _ = require('microdash'),
expect = require('chai').expect,
tools = require('../../../tools');
describe('PHP Parser grammar generator function statement integration', function () {
var parser;
beforeEach(function () {
parser = tools.createParser();
});
_.each({
'declaring a generator that yields only values': {
code: '<?php function myGenerator() { yield "first"; print "middle"; yield "last"; }',
expectedAST: {
name: 'N_PROGRAM',
statements: [{
name: 'N_FUNCTION_STATEMENT',
func: {
name: 'N_STRING',
string: 'myGenerator'
},
generator: true,
args: [],
body: {
name: 'N_COMPOUND_STATEMENT',
statements: [{
name: 'N_EXPRESSION_STATEMENT',
expression: {
name: 'N_YIELD_EXPRESSION',
value: {
name: 'N_STRING_LITERAL',
string: 'first'
}
}
}, {
name: 'N_EXPRESSION_STATEMENT',
expression: {
name: 'N_PRINT_EXPRESSION',
operand: {
name: 'N_STRING_LITERAL',
string: 'middle'
}
}
}, {
name: 'N_EXPRESSION_STATEMENT',
expression: {
name: 'N_YIELD_EXPRESSION',
value: {
name: 'N_STRING_LITERAL',
string: 'last'
}
}
}]
}
}]
}
}
}, function (scenario, description) {
describe(description, function () {
// Pretty-print the code strings so any non-printable characters are readable.
describe('when the code is ' + JSON.stringify(scenario.code) + ' ?>', function () {
it('should return the expected AST', function () {
expect(parser.parse(scenario.code)).to.deep.equal(scenario.expectedAST);
});
});
});
});
});