alias.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. describe('aliases', function() {
  3. describe('standard', function() {
  4. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias.js');
  5. var found = docSet.getByLongname('myObject').filter(function($) {
  6. return !($.undocumented);
  7. });
  8. var foundMember = docSet.getByLongname('myObject.myProperty');
  9. it('When a symbol is given an alias it is documented as if the name is the alias value.', function() {
  10. expect(found[0].longname).toEqual('myObject');
  11. });
  12. it('When a symbol is a member of an alias it is documented as if the memberof is the alias value.', function() {
  13. expect(foundMember[0].longname).toEqual('myObject.myProperty');
  14. expect(foundMember[0].memberof).toEqual('myObject');
  15. });
  16. });
  17. it('When a symbol is a member of an alias of a nested name it is documented as if the memberof is the nested alias value.', function() {
  18. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias2.js');
  19. var foundMember = docSet.getByLongname('ns.Myclass#myProperty');
  20. expect(foundMember[0].longname).toEqual('ns.Myclass#myProperty');
  21. expect(foundMember[0].name).toEqual('myProperty');
  22. expect(foundMember[0].memberof).toEqual('ns.Myclass');
  23. expect(foundMember[0].scope).toEqual('instance');
  24. });
  25. it('When a symbol is a member of an aliased class, a this-variable is documented as if it were a member that class.', function() {
  26. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias3.js');
  27. var tcmValue = docSet.getByLongname('trackr.CookieManager#value')[0];
  28. expect(tcmValue.memberof).toEqual('trackr.CookieManager');
  29. });
  30. it('When a symbol is a function expression that has an alias, the symbol should get the correct longname', function() {
  31. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias4.js');
  32. var jacketClass = docSet.getByLongname('module:jacket').filter(function($) {
  33. return $.kind === 'class';
  34. });
  35. expect(jacketClass.length).toBe(1);
  36. expect(jacketClass[0].longname).toBe('module:jacket');
  37. });
  38. describe('formats', function() {
  39. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias5.js');
  40. var toast = docSet.getByLongname('Toaster#toast')[0];
  41. var getInstance = docSet.getByLongname('Toaster.getInstance')[0];
  42. var clean = docSet.getByLongname('Toaster#clean')[0];
  43. it('should work when the alias value specifies an instance member', function() {
  44. expect(toast).toBeDefined();
  45. expect(toast.name).toBe('toast');
  46. expect(toast.memberof).toBe('Toaster');
  47. expect(toast.scope).toBe('instance');
  48. });
  49. it('should work when the alias value specifies a static member', function() {
  50. expect(getInstance).toBeDefined();
  51. expect(getInstance.name).toBe('getInstance');
  52. expect(getInstance.memberof).toBe('Toaster');
  53. expect(getInstance.scope).toBe('static');
  54. });
  55. it('should work when the alias value only specifies the short name', function() {
  56. expect(clean).toBeDefined();
  57. expect(clean.name).toBe('clean');
  58. expect(clean.memberof).toBe('Toaster');
  59. expect(clean.scope).toBe('instance');
  60. });
  61. });
  62. it('When a symbol is a constructor of a class with an alias, the constructor should get the correct longname', function() {
  63. var docSet = jasmine.getDocSetFromFile('test/fixtures/alias6.js');
  64. var constructor = docSet.getByLongname('module:example')[2];
  65. expect(constructor.undocumented).toBe(true);
  66. expect(constructor.name).toBe('module:example');
  67. expect(constructor.alias).toBe('module:example');
  68. });
  69. it('When a symbol is documented as a static member of <global>, its scope is "global" and not "static".', function() {
  70. var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js');
  71. var log = docSet.getByLongname('log')[0];
  72. expect(log.scope).toEqual('global');
  73. });
  74. it('When a symbol is documented as an instance member of <global>, its scope is "instance" and not "static".', function() {
  75. var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal2.js');
  76. var run = docSet.getByLongname('Test#run')[0];
  77. expect(run.scope).toEqual('instance');
  78. expect(run.memberof).toEqual('Test');
  79. });
  80. describe('resolving', function() {
  81. it('When a local reference has alias, put all members into aliased definition. Local modifications should be visible to outside.', function() {
  82. var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasresolve.js');
  83. var method = docSet.getByLongname('A.F.method');
  84. expect(method.length).toEqual(1);
  85. });
  86. it('When a reference in an outer scope has alias, put all members into aliased definition. Local modifications are visible to outside.', function() {
  87. var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasresolve2.js');
  88. var method = docSet.getByLongname('A.F.method');
  89. expect(method.length).toEqual(1);
  90. });
  91. });
  92. });