namespaces.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*global describe it */
  2. var spawn = require('child_process').spawn;
  3. var assert = require('assert');
  4. var generators = require('..');
  5. describe('Alias and namespaces', function () {
  6. it('env.namespace()', function () {
  7. var env = generators();
  8. assert.equal(env.namespace('backbone/all/index.js'), 'backbone:all');
  9. assert.equal(env.namespace('backbone/all/main.js'), 'backbone:all');
  10. assert.equal(env.namespace('backbone/all'), 'backbone:all');
  11. assert.equal(env.namespace('backbone/all.js'), 'backbone:all');
  12. assert.equal(env.namespace('backbone.js'), 'backbone');
  13. assert.equal(env.namespace('generator-backbone/all.js'), 'backbone:all');
  14. assert.equal(env.namespace('generator-mocha/backbone/model/index.js'), 'mocha:backbone:model');
  15. assert.equal(env.namespace('generator-mocha/backbone/model.js'), 'mocha:backbone:model');
  16. assert.equal(env.namespace('node_modules/generator-mocha/backbone/model.js'), 'mocha:backbone:model');
  17. assert.equal(env.namespace('../local/stuff'), 'local:stuff');
  18. assert.equal(env.namespace('./local/stuff'), 'local:stuff');
  19. assert.equal(env.namespace('././local/stuff'), 'local:stuff');
  20. assert.equal(env.namespace('../../local/stuff'), 'local:stuff');
  21. });
  22. it('should work with mixed similar lookups', function () {
  23. var env = generators();
  24. // Order is important, smaller lookup must come first here
  25. env.appendLookup('foo');
  26. env.appendLookup('foo/bar');
  27. assert.equal(env.namespace('foo/gen/all'), 'gen:all');
  28. assert.equal(env.namespace('foo/bar/gen/all'), 'gen:all');
  29. });
  30. it('should work with weird paths', function () {
  31. var env = generators();
  32. assert.equal(env.namespace('////gen/all'), 'gen:all');
  33. assert.equal(env.namespace('generator-backbone///all.js'), 'backbone:all');
  34. assert.equal(env.namespace('generator-backbone/././all.js'), 'backbone:all');
  35. assert.equal(env.namespace('generator-backbone/generator-backbone/all.js'), 'backbone:all');
  36. });
  37. it('should work in different OS', function () {
  38. var env = generators();
  39. assert.equal(env.namespace('backbone\\all\\main.js'), 'backbone:all');
  40. assert.equal(env.namespace('backbone\\all'), 'backbone:all');
  41. assert.equal(env.namespace('backbone\\all.js'), 'backbone:all');
  42. });
  43. });