PageRenderTime 129ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/test/coffee-dox-test.coffee

http://github.com/cpsubrian/coffee-dox
CoffeeScript | 254 lines | 204 code | 44 blank | 6 comment | 0 complexity | 0bff36c26243ab21ca99d9d042b39bc1 MD5 | raw file
Possible License(s): MIT
  1. ###
  2. Vows tests for CoffeeDox
  3. ###
  4. cdox = require '../'
  5. should = require 'should'
  6. vows = require 'vows'
  7. fixture = require './helpers/fixture'
  8. quickVows = require './helpers/quick-vows'
  9. # Create the test suite.
  10. suite = vows.describe('CoffeeDox')
  11. # App Tests
  12. suite.addBatch
  13. 'Application version':
  14. topic: cdox.version
  15. 'should be a valid version string': (version) ->
  16. version.should.match /^\d+\.\d+\.\d+$/
  17. # Parser Test
  18. suite.addBatch
  19. 'When reading a file with comment blocks':
  20. topic: fixture 'a.coffee'
  21. 'and parsing it,':
  22. topic: (str) -> cdox.parseComments str
  23. 'the file comment meta': quickVows
  24. topic: (comments) -> comments[0]
  25. 'it should have property': 'ignore'
  26. 'the ignore should be true': ''
  27. 'the description full should equal': '<p>A<br />Copyright (c) 2010 Author Name &lt;Author Email&gt;<br />MIT Licensed</p>'
  28. 'the description summary should equal': '<p>A<br />Copyright (c) 2010 Author Name &lt;Author Email&gt;<br />MIT Licensed</p>'
  29. 'the description body should equal': ''
  30. 'the tags should be empty': ''
  31. 'the version comment meta': quickVows
  32. topic: (comments) -> comments[1]
  33. 'it should have property': 'ignore'
  34. 'the ignore should be false': ''
  35. 'the description full should equal': '<p>Library version.</p>'
  36. 'the description summary should equal': '<p>Library version.</p>'
  37. 'the description body should equal': ''
  38. 'the tags should be empty': ''
  39. 'When reading a file with comment tags':
  40. topic: fixture 'b.coffee'
  41. 'and parsing it,':
  42. topic: (str) -> cdox.parseComments str
  43. 'the version comment meta': quickVows
  44. topic: (comments) -> comments[0]
  45. 'the description summary should equal': '<p>Library version.</p>'
  46. 'the description full should equal': '<p>Library version.</p>'
  47. 'the tags should have length': 2
  48. 'the tags 0 type should equal': 'type'
  49. 'the tags 0 types should eql': ['String']
  50. 'the tags 1 type should equal': 'api'
  51. 'the tags 1 visibility should equal': 'public'
  52. 'the ctx type should equal': 'property'
  53. 'the ctx receiver should equal': 'exports'
  54. 'the ctx name should equal': 'version'
  55. 'the ctx value should equal': "'0.0.1'"
  56. 'the parse comment meta': quickVows
  57. topic: (comments) -> comments[1]
  58. 'the description summary should equal': '<p>Parse the given <code>str</code>.</p>'
  59. 'the description body should equal': '<h2>Examples</h2>\n\n<pre><code>parse(str)\n// =&amp;gt; "wahoo"\n</code></pre>'
  60. 'the description full should equal': '<p>Parse the given <code>str</code>.</p>\n\n<h2>Examples</h2>\n\n<pre><code>parse(str)\n// =&amp;gt; "wahoo"\n</code></pre>'
  61. 'the tags 0 type should equal': 'param'
  62. 'the tags 0 name should equal': 'str'
  63. 'the tags 0 description should equal': 'to parse'
  64. 'the tags 0 types should eql': ['String', 'Buffer']
  65. 'the tags 1 type should equal': 'return'
  66. 'the tags 1 types should eql': ['String']
  67. 'the tags 2 visibility should equal': 'public'
  68. 'When parsing complex comments,':
  69. topic: fixture 'c.coffee'
  70. 'the parsed comments':
  71. topic: (str) -> cdox.parseComments str
  72. 'should have the correct file meta': (comments) ->
  73. file = comments[0]
  74. file.tags.should.be.empty
  75. file.description.full.should.equal '<p>Dox<br />Copyright (c) 2011 Brian Link &lt;<a href=\'mailto:cpsubrian@gmail.com\'>cpsubrian@gmail.com</a>&gt;<br />MIT Licensed</p>'
  76. file.ignore.should.be.true
  77. 'should have the correct mods meta': (comments) ->
  78. mods = comments[1]
  79. mods.tags.should.be.empty
  80. mods.description.full.should.equal '<p>Module dependencies.</p>'
  81. mods.description.summary.should.equal '<p>Module dependencies.</p>'
  82. mods.description.body.should.equal ''
  83. mods.ignore.should.be.false
  84. mods.code.should.equal 'markdown = require(\'github-flavored-markdown\').parse\n{escape} = require \'./utils\''
  85. mods.ctx.type.should.equal 'declaration'
  86. mods.ctx.name.should.equal 'markdown'
  87. mods.ctx.value.should.equal 'require(\'github-flavored-markdown\').parse'
  88. 'should have the correct version meta': (comments) ->
  89. version = comments[2]
  90. version.tags.should.be.empty
  91. version.description.full.should.equal '<p>Library version.</p>'
  92. 'should have the correct parseComments meta': (comments) ->
  93. parseComments = comments[3]
  94. parseComments.tags.should.have.length 4
  95. parseComments.ctx.type.should.equal 'method'
  96. parseComments.ctx.receiver.should.equal 'exports'
  97. parseComments.ctx.name.should.equal 'parseComments'
  98. parseComments.description.full.should.equal '<p>Parse comments in the given string of <code>js</code>.</p>'
  99. parseComments.description.summary.should.equal '<p>Parse comments in the given string of <code>js</code>.</p>'
  100. parseComments.description.body.should.equal ''
  101. 'should have the correct parseComment meta': (comments) ->
  102. parseComment = comments[4]
  103. parseComment.tags.should.have.length 4
  104. parseComment.description.summary.should.equal '<p>Parse the given comment <code>str</code>.</p>'
  105. parseComment.description.full.should.equal '<p>Parse the given comment <code>str</code>.</p>\n\n<h2>The comment object returned contains the following</h2>\n\n<ul>\n<li><code>tags</code> array of tag objects</li>\n<li><code>description</code> the first line of the comment</li>\n<li><code>body</code> lines following the description</li>\n<li><code>content</code> both the description and the body</li>\n<li><code>isPrivate</code> true when "@api private" is used</li>\n</ul>'
  106. parseComment.description.body.should.equal '<h2>The comment object returned contains the following</h2>\n\n<ul>\n<li><code>tags</code> array of tag objects</li>\n<li><code>description</code> the first line of the comment</li>\n<li><code>body</code> lines following the description</li>\n<li><code>content</code> both the description and the body</li>\n<li><code>isPrivate</code> true when "@api private" is used</li>\n</ul>'
  107. 'should have the correct escape meta': (comments) ->
  108. escape = comments.pop()
  109. escape.tags.should.have.length 3
  110. escape.description.full.should.equal '<p>Escape the given <code>html</code>.</p>'
  111. escape.ctx.type.should.equal 'method'
  112. escape.ctx.name.should.equal 'escape'
  113. 'When parsing a complete code sample,':
  114. topic: fixture 'd.coffee'
  115. 'the parsed comments':
  116. topic: (str) -> cdox.parseComments str
  117. 'should have the correct description, tags, and code': (comments) ->
  118. first = comments.shift()
  119. first.tags.should.have.length 3
  120. first.description.full.should.equal '<p>Parse tag type string "{Array|Object}" etc.</p>'
  121. first.description.summary.should.equal '<p>Parse tag type string "{Array|Object}" etc.</p>'
  122. first.description.body.should.equal ''
  123. first.ctx.type.should.equal 'method'
  124. first.ctx.receiver.should.equal 'exports'
  125. first.ctx.name.should.equal 'parseTagTypes'
  126. first.code.should.equal 'exports.parseTagTypes = (str) ->\n str.replace(\'foo\', \'bar\').split(\',\')'
  127. 'When parsing comment tags again,':
  128. topic: fixture 'b.coffee'
  129. 'the parse comments':
  130. topic: (str) -> cdox.parseComments str
  131. 'should have the correct code segments': (comments) ->
  132. version = comments.shift()
  133. parse = comments.shift()
  134. version.code.should.equal "exports.version = '0.0.1'"
  135. parse.code.should.equal 'exports.parse = (str) ->\n "wahoo"'
  136. 'When parsing a function expression': quickVows
  137. topic: cdox.parseCodeContext 'foo = () ->\n'
  138. 'the type should equal': 'function'
  139. 'the name should equal': 'foo'
  140. 'When parsing a prototype method': quickVows
  141. topic: cdox.parseCodeContext 'User::save = ->\n'
  142. 'the type should equal': 'method'
  143. 'the constructor should equal': 'User'
  144. 'the name should equal': 'save'
  145. 'When parsing a prototype property': quickVows
  146. topic: cdox.parseCodeContext 'Database::enabled = true\nasdf'
  147. 'the type should equal': 'property'
  148. 'the constructor should equal': 'Database'
  149. 'the name should equal': 'enabled'
  150. 'the value should equal': 'true'
  151. 'When parsing a method': quickVows
  152. topic: cdox.parseCodeContext 'user.save = () ->'
  153. 'the type should equal': 'method'
  154. 'the receiver should equal': 'user'
  155. 'the name should equal': 'save'
  156. 'When parsing a property': quickVows
  157. topic: cdox.parseCodeContext 'user.name = "Brian"\nasdf'
  158. 'the type should equal': 'property'
  159. 'the receiver should equal': 'user'
  160. 'the name should equal': 'name'
  161. 'the value should equal': '"Brian"'
  162. 'When parsing a declaration': quickVows
  163. topic: cdox.parseCodeContext 'name = "Brian"\nadf'
  164. 'the type should equal': 'declaration'
  165. 'the name should equal': 'name'
  166. 'the value should equal': '"Brian"'
  167. 'When parsing a @constructor tag': quickVows
  168. topic: cdox.parseTag '@constructor'
  169. 'the type should equal': 'constructor'
  170. 'When parsing a @see tag,':
  171. 'that only has a url': quickVows
  172. topic: cdox.parseTag '@see http://google.com'
  173. 'the type should equal': 'see'
  174. 'the title should equal': ''
  175. 'the url should equal': 'http://google.com'
  176. 'that has a title and url': quickVows
  177. topic: cdox.parseTag '@see Google http://google.com'
  178. 'the type should equal': 'see'
  179. 'the title should equal': 'Google'
  180. 'the url should equal': 'http://google.com'
  181. 'that has a reference to other code': quickVows
  182. topic: cdox.parseTag '@see exports.parseComment'
  183. 'the type should equal': 'see'
  184. 'the local should equal': 'exports.parseComment'
  185. 'When parsing an @api tag': quickVows
  186. topic: cdox.parseTag '@api private'
  187. 'the type should equal': 'api'
  188. 'the visibility should equal': 'private'
  189. 'When parsing a @type tag': quickVows
  190. topic: cdox.parseTag '@type {String}'
  191. 'the type should equal': 'type'
  192. 'the types should eql': ['String']
  193. 'When parsing a @param tag': quickVows
  194. topic: cdox.parseTag '@param {String|Buffer}'
  195. 'the type should equal': 'param'
  196. 'the types should eql': ['String', 'Buffer']
  197. 'the name should equal': ''
  198. 'the description should equal': ''
  199. 'When parsing a @param tag with and name and description': quickVows
  200. topic: cdox.parseTag '@param {String} name - A person\'s name'
  201. 'the type should equal': 'param'
  202. 'the types should eql': ['String']
  203. 'the name should equal': 'name'
  204. 'the description should equal': '- A person\'s name'
  205. 'When parsing a @return tag': quickVows
  206. topic: cdox.parseTag '@return {String} a normal string'
  207. 'the type should equal': 'return'
  208. 'the types should eql': ['String']
  209. 'the description should equal': 'a normal string'
  210. suite.export module