-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for PHP 'use' statement to grammar
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
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
88 changes: 88 additions & 0 deletions
88
tests/bdd/integration/languages/PHP/grammar/statements/useTest.js
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,88 @@ | ||
/* | ||
* Uniter - JavaScript PHP interpreter | ||
* Copyright 2013 Dan Phillimore (asmblah) | ||
* http://asmblah.github.com/uniter/ | ||
* | ||
* Released under the MIT license | ||
* https://github.com/asmblah/uniter/raw/master/MIT-LICENSE.txt | ||
*/ | ||
|
||
/*global define */ | ||
define([ | ||
'../../tools', | ||
'js/util' | ||
], function ( | ||
tools, | ||
util | ||
) { | ||
'use strict'; | ||
|
||
describe('PHP Parser grammar use statement integration', function () { | ||
var parser; | ||
|
||
beforeEach(function () { | ||
parser = tools.createParser(); | ||
}); | ||
|
||
util.each({ | ||
'use outside of namespace for simple import': { | ||
code: 'use Toolkit;', | ||
expectedAST: { | ||
name: 'N_PROGRAM', | ||
statements: [{ | ||
name: 'N_USE_STATEMENT', | ||
uses: [{ | ||
source: { | ||
name: 'N_CLASS_REFERENCE', | ||
path: 'Toolkit' | ||
} | ||
}] | ||
}] | ||
} | ||
}, | ||
'use outside of namespace for simple aliasing': { | ||
code: 'use Uniter as Library;', | ||
expectedAST: { | ||
name: 'N_PROGRAM', | ||
statements: [{ | ||
name: 'N_USE_STATEMENT', | ||
uses: [{ | ||
source: { | ||
name: 'N_CLASS_REFERENCE', | ||
path: 'Uniter' | ||
}, | ||
alias: 'Library' | ||
}] | ||
}] | ||
} | ||
}, | ||
'use outside of namespace for aliasing deeply nested namespace': { | ||
code: 'use Framework\\Network\\Http\\Request as MyFrameworkRequest;', | ||
expectedAST: { | ||
name: 'N_PROGRAM', | ||
statements: [{ | ||
name: 'N_USE_STATEMENT', | ||
uses: [{ | ||
source: { | ||
name: 'N_CLASS_REFERENCE', | ||
path: 'Framework\\Network\\Http\\Request' | ||
}, | ||
alias: 'MyFrameworkRequest' | ||
}] | ||
}] | ||
} | ||
} | ||
}, function (scenario, description) { | ||
describe(description, function () { | ||
var code = '<?php ' + scenario.code; | ||
|
||
// Pretty-print the code strings so any non-printable characters are readable | ||
describe('when the code is ' + JSON.stringify(code) + ' ?>', function () { | ||
it('should return the expected AST', function () { | ||
expect(parser.parse(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