-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for generator closures & methods and support yielding keys
- Loading branch information
Showing
3 changed files
with
298 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 yield expression integration', function () { | ||
var parser; | ||
|
||
beforeEach(function () { | ||
parser = tools.createParser(); | ||
}); | ||
|
||
_.each({ | ||
'yielding an integer value': { | ||
code: '<?php yield 21;', | ||
expectedAST: { | ||
name: 'N_PROGRAM', | ||
statements: [{ | ||
name: 'N_EXPRESSION_STATEMENT', | ||
expression: { | ||
name: 'N_YIELD_EXPRESSION', | ||
key: null, | ||
value: { | ||
name: 'N_INTEGER', | ||
number: '21' | ||
} | ||
} | ||
}] | ||
} | ||
}, | ||
'yielding a string key and float value': { | ||
code: '<?php yield "my key" => 123.456;', | ||
expectedAST: { | ||
name: 'N_PROGRAM', | ||
statements: [{ | ||
name: 'N_EXPRESSION_STATEMENT', | ||
expression: { | ||
name: 'N_YIELD_EXPRESSION', | ||
key: { | ||
name: 'N_STRING_LITERAL', | ||
string: 'my key' | ||
}, | ||
value: { | ||
name: 'N_FLOAT', | ||
number: 123.456 | ||
} | ||
} | ||
}] | ||
} | ||
} | ||
}, 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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters