overloadHelper.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. describe('plugins/overloadHelper', function() {
  3. var env = require('jsdoc/env');
  4. var path = require('jsdoc/path');
  5. var docSet;
  6. var parser = jasmine.createParser();
  7. var pluginPath = 'plugins/overloadHelper';
  8. var pluginPathResolved = path.resolve(env.dirname, pluginPath);
  9. var plugin = require(pluginPathResolved);
  10. require('jsdoc/plugins').installPlugins([pluginPathResolved], parser);
  11. docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/overloadHelper.js', parser);
  12. it('should exist', function() {
  13. expect(plugin).toBeDefined();
  14. expect(typeof plugin).toBe('object');
  15. });
  16. it('should export handlers', function() {
  17. expect(plugin.handlers).toBeDefined();
  18. expect(typeof plugin.handlers).toBe('object');
  19. });
  20. it('should export a "newDoclet" handler', function() {
  21. expect(plugin.handlers.newDoclet).toBeDefined();
  22. expect(typeof plugin.handlers.newDoclet).toBe('function');
  23. });
  24. it('should export a "parseComplete" handler', function() {
  25. expect(plugin.handlers.parseComplete).toBeDefined();
  26. expect(typeof plugin.handlers.parseComplete).toBe('function');
  27. });
  28. describe('newDoclet handler', function() {
  29. it('should not add unique longnames to constructors', function() {
  30. var soup = docSet.getByLongname('Soup');
  31. var soup1 = docSet.getByLongname('Soup()');
  32. var soup2 = docSet.getByLongname('Soup(spiciness)');
  33. expect(soup.length).toBe(2);
  34. expect(soup1.length).toBe(0);
  35. expect(soup2.length).toBe(0);
  36. });
  37. it('should add unique longnames to methods', function() {
  38. var slurp = docSet.getByLongname('Soup#slurp');
  39. var slurp1 = docSet.getByLongname('Soup#slurp()');
  40. var slurp2 = docSet.getByLongname('Soup#slurp(dBA)');
  41. expect(slurp.length).toBe(0);
  42. expect(slurp1.length).toBe(1);
  43. expect(slurp2.length).toBe(1);
  44. });
  45. it('should update the "variation" property of the method', function() {
  46. var slurp1 = docSet.getByLongname('Soup#slurp()')[0];
  47. var slurp2 = docSet.getByLongname('Soup#slurp(dBA)')[0];
  48. expect(slurp1.variation).toBe('');
  49. expect(slurp2.variation).toBe('dBA');
  50. });
  51. it('should not add to or change existing variations that are unique', function() {
  52. var salt1 = docSet.getByLongname('Soup#salt');
  53. var salt2 = docSet.getByLongname('Soup#salt(mg)');
  54. expect(salt1.length).toBe(1);
  55. expect(salt2.length).toBe(1);
  56. });
  57. it('should not duplicate the names of existing numeric variations', function() {
  58. var heat1 = docSet.getByLongname('Soup#heat(1)');
  59. var heat2 = docSet.getByLongname('Soup#heat(2)');
  60. var heat3 = docSet.getByLongname('Soup#heat(3)');
  61. expect(heat1.length).toBe(1);
  62. expect(heat2.length).toBe(1);
  63. expect(heat3.length).toBe(1);
  64. });
  65. it('should replace identical variations with new, unique variations', function() {
  66. var discard1 = docSet.getByLongname('Soup#discard()');
  67. var discard2 = docSet.getByLongname('Soup#discard(container)');
  68. expect(discard1.length).toBe(1);
  69. expect(discard2.length).toBe(1);
  70. });
  71. });
  72. describe('parseComplete handler', function() {
  73. // disabled because on the second run, each comment is being parsed twice; who knows why...
  74. xit('should not retain parse results between parser runs', function() {
  75. parser.clear();
  76. docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/overloadHelper.js', parser);
  77. var heat = docSet.getByLongname('Soup#heat(4)');
  78. expect(heat.length).toBe(0);
  79. });
  80. });
  81. });